###前提・実現したいこと
unityのGameObjectのMainCamaraのCameraコンポーネントのorthographicSizeをスクリプトから操作したい。
###発生している問題・エラーメッセージ
orthographicSizeがゲームプレイ時に反映されない。
###該当のソースコード
using UnityEngine; using System.Collections; public class CameraFollow : MonoBehaviour { public Transform target; public float smoothing = 5f; Vector3 offset; Camera camera; float ogsize; void Start() { offset = transform.position - target.position; camera = GameObject.Find("Main Camera").GetComponent<Camera>(); ogsize = camera.orthographicSize; } void Update() { if (ogsize == 4.5 && Input.GetButtonDown ("Fire2")) { ogsize = 9f; Debug.Log (ogsize); } else if (ogsize == 9 && Input.GetButtonDown ("Fire2")) { ogsize = 4.5f; Debug.Log (ogsize); } } void FixedUpdate() { Vector3 targetCamPos = target.position + offset; transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime); } }
###試したこと
void Update()のDebug.Log (ogsize);により確認した結果、
マウスを右クリックする度に、9と4.5は表示されるので、orthographicSizeの数値は変更されてはいます。
しかし、ゲーム画面上ではカメラには何も動きがありません。
インスペクタ上でorthographicSizeを変更するとゲーム画面上のカメラは動きます。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/04 03:53