84 lines
1.9 KiB
C#
84 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class VirusBehaviour : MonoBehaviour, IPointerClickHandler
|
|
{
|
|
public bool isAlive = true;
|
|
|
|
public Sprite dead, rs;
|
|
private Animator anim;
|
|
private Coroutine deathLoop;
|
|
private float timeToWait = 2;
|
|
private bool killed = false;
|
|
public void Awake()
|
|
{
|
|
SetTimer();
|
|
}
|
|
|
|
public void SetTimer()
|
|
{
|
|
WhackSpawnManager info = WhackSpawnManager.instance;
|
|
if (info.waveCount >= 0 && info.waveCount <= 5)
|
|
{
|
|
timeToWait = 2.5f;
|
|
}
|
|
else if (info.waveCount > 5 && info.waveCount <= 10)
|
|
{
|
|
timeToWait = 2f;
|
|
}
|
|
else if (info.waveCount > 10 && info.waveCount <= 20)
|
|
{
|
|
timeToWait = 1.5f;
|
|
}
|
|
else if (info.waveCount > 20)
|
|
{
|
|
timeToWait = 1;
|
|
}
|
|
deathLoop = StartCoroutine(TakeHealth());
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData data)
|
|
{
|
|
if(isAlive)
|
|
{
|
|
killed = true;
|
|
Death();
|
|
StopCoroutine(deathLoop);
|
|
WhackManager.instance.AddPoint();
|
|
}
|
|
}
|
|
|
|
public void Death()
|
|
{
|
|
if (!anim)
|
|
{
|
|
anim = GetComponent<Animator>();
|
|
}
|
|
isAlive = false;
|
|
if (killed)
|
|
{
|
|
GetComponent<Image>().sprite = dead;
|
|
anim.SetTrigger("Die");
|
|
}
|
|
else
|
|
{
|
|
GetComponent<Image>().sprite = rs;
|
|
anim.SetTrigger("Rs");
|
|
}
|
|
|
|
|
|
Destroy(this.gameObject, .5f);
|
|
transform.parent.GetComponent<WhackSpawner>().SpawnDied();
|
|
}
|
|
|
|
IEnumerator TakeHealth()
|
|
{
|
|
yield return new WaitForSeconds(timeToWait);
|
|
WhackManager.instance.RemoveHealth();
|
|
Death();
|
|
}
|
|
}
|