xirang/Assets/scripts/enemy.cs
杨号敬 5cce41cb28 add
2024-11-27 00:06:28 +08:00

41 lines
828 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Enemy : MonoBehaviour
{
public NavMeshAgent _agent;
public int bloodvolume;
public Transform player;
// 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
Destroy(this.gameObject);
}
}
public void EnemyHpDown(int hp)
{
bloodvolume -= hp;
}
public void setMoveTo(Transform target)
{
_agent.SetDestination(target.position);
}
}