too many if statements
This commit is contained in:
parent
533f137c48
commit
17b1a1e367
7 changed files with 55 additions and 20 deletions
|
|
@ -11,15 +11,20 @@ public class Entity : MonoBehaviour
|
|||
[Header("Movement")]
|
||||
public int maxMovement;
|
||||
public TileObject currentTile;
|
||||
public float moveAnimSpeed;
|
||||
[SerializeField] private float moveAnimSpeed;
|
||||
|
||||
[Header("Flags")]
|
||||
public bool canMove = true;
|
||||
public bool invincible;
|
||||
|
||||
[Header("Animation")]
|
||||
[SerializeField] private SpriteRenderer[] spriteRenderers;
|
||||
[SerializeField] private float damageColorChangeSpeed;
|
||||
|
||||
public virtual void TakeDamage(float damage)
|
||||
{
|
||||
health -= damage;
|
||||
StartCoroutine(DamageAnimation());
|
||||
if (health <= 0)
|
||||
{
|
||||
OnKillEffects();
|
||||
|
|
@ -61,4 +66,20 @@ public class Entity : MonoBehaviour
|
|||
}
|
||||
FinishedMovement();
|
||||
}
|
||||
private IEnumerator DamageAnimation()
|
||||
{
|
||||
float currentState = 0;
|
||||
while (currentState < 1)
|
||||
{
|
||||
currentState += Time.deltaTime * damageColorChangeSpeed;
|
||||
foreach (SpriteRenderer spritepart in spriteRenderers)
|
||||
{
|
||||
if (spritepart)
|
||||
{
|
||||
spritepart.color = Color.Lerp(Color.gray, Color.white, currentState);
|
||||
}
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue