NullReferenceException: Object reference not set to an instance of an object
EvasiveManeuver.Start () (at Assets/Script/EvasiveManeuver.cs:22)
とエラーが出ました。
using UnityEngine; using System.Collections; public class EvasiveManeuver : MonoBehaviour { public float dodge; public float smoothing; public float tilt; public Vector2 startWait; public Vector2 maneuverTime; public Vector2 maneuverWait; public Boundary boundary; public Transform playerTransform; private float currentSpeed; private float targetManeuver; private Rigidbody rb; // Use this for initialization void Start () { rb = GetComponent <Rigidbody> (); playerTransform = GameObject.FindGameObjectWithTag ("Player").transform; currentSpeed = rb.velocity.z; StartCoroutine (Evade ()); } IEnumerator Evade() { yield return new WaitForSeconds (Random.Range (startWait.x, startWait.y)); while (true) { targetManeuver = Random.Range (1, dodge) * -Mathf.Sign (transform.position.x); yield return new WaitForSeconds (Random.Range (maneuverTime.x, maneuverTime.y)); targetManeuver = 0; yield return new WaitForSeconds (Random.Range (maneuverWait.x, maneuverWait.y)); } } void FixedUpdate () { float newManeuver = Mathf.MoveTowards (rb.velocity.x, targetManeuver, Time.deltaTime * smoothing); rb.velocity = new Vector3 (newManeuver, 0.0f, currentSpeed); rb.position = new Vector3( Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax) ); rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt); } }
とコードを書き
playerTransform = GameObject.FindGameObjectWithTag ("Player").transform;
の部分がおかしいと指摘されました。
これはunityのインスペクタ側に必要なものがないエラーなのでしょうか、
それともソースコードに必要なものがないのでしょうか?
どちらに何を付け加えたら良いのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。