target(プレイヤー)と敵が接触した時、targetをdestroyしたため、agent.destination = target.transform.position;のあたりで
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
というエラーメッセージが出ました。
どのように修正すれば、このエラーが起きなくなるかのご教授お願いします。
using
1using System.Collections.Generic; 2using UnityEngine; 3 4// ★追加(ポイント) 5using UnityEngine.AI; 6 7public class Chase : MonoBehaviour 8{ 9 10 public GameObject target; 11 private NavMeshAgent agent; 12 13 void Start() 14 { 15 agent = GetComponent<NavMeshAgent>(); 16 } 17 18 void Update() 19 { 20 21 // 敵の目的地にターゲットの位置を設定する。 22 agent.destination = target.transform.position; 23 24 } 25} 26コード
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/29 01:13