追いかけてくる敵を作る(追跡機能)




追跡機能の実装
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 追加
using UnityEngine.AI;
public class ChaseEnemy : MonoBehaviour
{
private GameObject target;
private NavMeshAgent agent;
void Start()
{
// (復習)Find()の働きは?
target = GameObject.Find("Tank");
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
if(target) // (復習)この条件の意味は?
{
// targetの位置を目的地に設定する。
agent.destination = target.transform.position;
}
}
}











【2021版】BattleTank(基礎/全33回)
他のコースを見る



追跡機能の実装
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 追加
using UnityEngine.AI;
public class ChaseEnemy : MonoBehaviour
{
private GameObject target;
private NavMeshAgent agent;
void Start()
{
// (復習)Find()の働きは?
target = GameObject.Find("Tank");
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
if(target) // (復習)この条件の意味は?
{
// targetの位置を目的地に設定する。
agent.destination = target.transform.position;
}
}
}











追いかけてくる敵を作る(追跡機能)