1
Fork 0
mirror of https://github.com/Steffo99/beat-td.git synced 2024-11-25 16:54:18 +00:00
beat-td/Assets/Scripts/EnemyStatus.cs

52 lines
1.3 KiB
C#
Raw Normal View History

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