using System.Collections.Generic;
using UnityEngine;
//using UnityEngine.AI;
public class monster04 : MonoBehaviour {
//導航系統
//怪物的血量
public float MonsterHp = 10;
NavMeshAgent MonsterAI;
//判斷怪物攻擊時間
public float Timer;
//判斷是否能再次攻擊時間
public float timeBetweenAttacks = 0;
//宣告怪物動畫控制器
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);
}
if (Timer > timeBetweenAttacks) {
//攻擊時間每秒 1
Timer -= Time.deltaTime;
}
}
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);
}
}
}
public void OnTriggerStay(Collider Other) {
//觸發物件Other的Tag標籤為Player
if (Other.gameObject.tag == "Player1") {
//如果攻擊時間大於攻擊間隔
if (Timer <= timeBetweenAttacks) {
//把攻擊時間歸零
MonsterAnim.SetBool("M_Attack_Bool",true);
Timer = 2.0f;
}
}
}
public void MonsterAtkAnimOff(){
MonsterAnim.SetBool("M_Attack_Bool",false);
Player1.GetComponent<player01>().PlayerLife -= 10;
}
}