using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using UnityEngine.AI;
public class monster04 : MonoBehaviour {
//導航系統
//怪物的血量
public float MonsterHp = 10;
NavMeshAgent MonsterAI;
//宣告怪物動畫控制器
Animator MonsterAnim;
//宣告玩家物件
public GameObject Player1;
// Use this for initialization
void Start () {
//導航元件MonsterAI = 自身物件中的NavMeshAgent屬性
MonsterAI = GetComponent<NavMeshAgent>();
MonsterAnim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
//如果玩家物件是空的
if(Player1 == null){
//尋找場景中Tag標籤為Player的物件
Player1 = GameObject.FindWithTag("Player1");
}else{
MonsterAI.destination = Player1.transform.position;
MonsterAnim.SetBool("M_Walk_Bool",true);
}
}
public void OnTriggerEnter (Collider Other)
{
//觸發物件Other的Tag標籤為Bullet
if (Other.gameObject.tag == "Bullet") {
//刪除Other物件
Destroy (Other.gameObject);
//怪物血量-1
MonsterHp -= 1;
//如果怪物血量小於0
if (MonsterHp <= 0) {
//刪除自身
Destroy (gameObject, 2.0f);
}
}
}
}