public class Enemy : MonoBehaviour { // targetには、Unity画面から追いかけたい対象のゲームオブジェクトを設定する public GameObject target; NavMeshAgent agent; Animator animator; void Start () { agent = GetComponent<NavMeshAgent> (); animator = GetComponentInChildren<Animator> (); } void Update () { // NavmeshAgentのdestinationに位置を設定すれば、自動的にその位置に向かって移動するようになる。 agent.destination = target.transform.position; animator.SetFloat ("Speed", agent.velocity.magnitude); } }