xi/Assets/scripts/Enemy.cs
杨号敬 e2f6da9586 FOG
2024-11-29 10:06:43 +08:00

48 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Enemy : MonoBehaviour
{
public NavMeshAgent _agent;
public float bloodvolume;
public Transform player;
public GameObject wupinPrefab;
public EnemySpawn enemySpawn;
public GameObject BloodPrefab;
// Start is called before the first frame update
void Start()
{
_agent = GetComponent<NavMeshAgent>();
player=GameObject.FindWithTag("Player").transform;
}
// Update is called once per frame
void Update()
{
setMoveTo(player);
if (bloodvolume <= 0)
{
//ToDo
enemySpawn.MinusNum();
GameObject Blood = Instantiate(BloodPrefab,this.transform.position + new Vector3(0,5,0), this.transform.rotation);
Destroy(Blood,0.5f);
GameObject wupin = Instantiate(wupinPrefab);
wupin.transform.position = this.transform.position+ new Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
Destroy(this.gameObject);
}
}
public void EnemyHpDown(float hp)
{
bloodvolume -= hp;
}
public void setMoveTo(Transform target)
{
_agent.SetDestination(target.position);
}
}