45 lines
1.0 KiB
C#
45 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
|
|
public class EnemyManager : MonoBehaviour
|
|
{
|
|
public float health = 100;
|
|
private NavMeshAgent navMeshAgent;
|
|
private PlayerManager player;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
player = FindObjectOfType<PlayerManager>();
|
|
navMeshAgent = GetComponent<NavMeshAgent>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
navMeshAgent.SetDestination(player.transform.position);
|
|
if (health <= 0)
|
|
{
|
|
Destroy(this.gameObject);
|
|
}
|
|
}
|
|
|
|
public void Damage()
|
|
{
|
|
WeaponManager weaponManager = player.weaponList[player.selectedWeapon].GetComponent<WeaponManager>();
|
|
if (weaponManager != null) {
|
|
health -= weaponManager.damage;
|
|
}
|
|
}
|
|
|
|
private void OnParticleCollision(GameObject other)
|
|
{
|
|
if (other.transform.tag == "Bullets")
|
|
{
|
|
Damage();
|
|
}
|
|
}
|
|
}
|