feat: Phase 1 complete - attack system, enemy damage, timers, and study notes summary
This commit is contained in:
42
Assets/Enemy.cs
Normal file
42
Assets/Enemy.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Enemy : MonoBehaviour
|
||||
{
|
||||
private SpriteRenderer sr;
|
||||
[SerializeField]private float redColorDuration = 1;
|
||||
public float currentTimeInGame;
|
||||
public float lastTimeWasDamaged;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
sr = GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
ChanceColorIfNeedes();
|
||||
}
|
||||
|
||||
private void ChanceColorIfNeedes()
|
||||
{
|
||||
currentTimeInGame = Time.time;
|
||||
if (currentTimeInGame > lastTimeWasDamaged + redColorDuration)
|
||||
{
|
||||
if (sr.color != Color.white)
|
||||
{
|
||||
TurnWhite();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage()
|
||||
{
|
||||
sr.color = Color.red;
|
||||
lastTimeWasDamaged = Time.time;
|
||||
}
|
||||
|
||||
private void TurnWhite()
|
||||
{
|
||||
sr.color = Color.white;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user