Skip to content

Instantly share code, notes, and snippets.

@todorok1
Last active April 16, 2018 07:55
Show Gist options
  • Save todorok1/6ee68df3d5c6ecee01f689dd7fb733a9 to your computer and use it in GitHub Desktop.
Save todorok1/6ee68df3d5c6ecee01f689dd7fb733a9 to your computer and use it in GitHub Desktop.
Unityチュートリアル・カメラの追従とズームイン・ズームアウトさせるスクリプト。
Vector3 GetMagnifiedOffset(){
// 規格化されたオフセットを取得
Vector3 normalizedOffset = offset.normalized;
// 『Sphere』オブジェクトとカメラの距離を取得
float offsetDistance = offset.magnitude;
// offsetDistanceに拡大率をかけて補正後の距離を取得
float magnifiedDistance = offsetDistance * (200f - magnify) / 100f;
// 規格化されたベクトルと拡大後の距離からオフセットを返す
Vector3 magnifiedOffset = magnifiedDistance * normalizedOffset;
return magnifiedOffset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment