こんばんは。
よろしくお願いします。
MissingComponentExceptionのエラーが出てしまいます。
###エラーの部分、
これがエラー、MissingComponentException: There is no 'GameObject' attached to the "Enemy" game object, but a script is trying to access it.
You probably need to add a GameObject to the game object "Enemy". Or your script needs to check if the component is attached before using it.
Chase.Update () (at Assets/Scenes/Scripts/Chase.cs:32)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Chase : MonoBehaviour
{
//ターゲットを追いかける宣言をする
public GameObject target;
//NavMeshAgentの宣言をする
private NavMeshAgent agent;
public GameObject enemy; // Start is called before the first frame update void Start() { //NavMeshAgentの情報を取得する agent = GetComponent<NavMeshAgent>(); target = GetComponent<GameObject>(); enemy = GetComponent<GameObject>(); } // Update is called once per frame void Update() { //ターゲットを追う Debug.Log(agent); agent.destination = target.transform.position; }
}
の agent.destination = target.transform.position;でエラーが出てしまいます。
どの部分が間違っているのでしょうか?
詳しく教えてください。
回答よろしくお願いします。
回答3件
あなたの回答
tips
プレビュー