GlobalGameJame/Assets/Scripts/EnemyManager.cs
Kotrba Filip a787aa09a3 Zombie 1
2020-02-01 08:52:46 +01:00

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();
}
}
}