1
Fork 0
mirror of https://github.com/Steffo99/beat-td.git synced 2024-11-23 15:54:18 +00:00
beat-td/Assets/Scripts/EnemyStatus.cs
2018-04-23 20:09:13 +02:00

55 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyStatus : MonoBehaviour {
public int livesCost = 1;
public int masks = 1;
public float baseHealth = 10f;
public float healthPerSecond = 0.6f;
private GameStatus gameStatus;
private SongData songData;
private float health;
void Start()
{
gameStatus = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameStatus>();
songData = GameObject.FindGameObjectWithTag("GameController").GetComponent<SongData>();
health = baseHealth + healthPerSecond * songData.songTime;
}
private void OnTriggerEnter2D(Collider2D collision)
{
KickCollision kickCollision = collision.GetComponent("KickCollision") as KickCollision;
SnareCollision snareCollision = collision.GetComponent("SnareCollision") as SnareCollision;
if (kickCollision != null)
{
health -= kickCollision.damage;
}
if (snareCollision != null)
{
health -= snareCollision.damage;
Destroy(snareCollision.gameObject);
}
if (collision.gameObject.tag == "Tower")
{
Destroy(collision.gameObject);
}
}
void Update()
{
if(health <= 0)
{
Die();
}
}
void Die()
{
gameStatus.money += masks;
Destroy(gameObject);
}
}