more abilities and fixes
This commit is contained in:
parent
cb4470f2d6
commit
fc2329a873
31 changed files with 268 additions and 52 deletions
67
Assets/Scripts/Entities/EntityStats.cs
Normal file
67
Assets/Scripts/Entities/EntityStats.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EntityStats : MonoBehaviour
|
||||
{
|
||||
public Entity thisEntity;
|
||||
[Header("Health")]
|
||||
public float health;
|
||||
public float maxHealth;
|
||||
[Header("Stats")]
|
||||
public float speed;
|
||||
public float jumpPower;
|
||||
[Header("State")]
|
||||
public bool isStalled;
|
||||
[Header("Ground Detection")]
|
||||
[SerializeField] private Transform groundCheck;
|
||||
[SerializeField] private LayerMask groundLayer;
|
||||
[Header("Attack Origin")]
|
||||
public Transform attackOriginPoint;
|
||||
public Transform attackOriginCenter;
|
||||
[Header("Abilities")]
|
||||
public List<Ability> abilities = new();
|
||||
[Header("Cache")]
|
||||
public Rigidbody2D rb;
|
||||
public SpriteRenderer sprite;
|
||||
public bool isFacingRight;
|
||||
public Color originalColor; //remove later
|
||||
public float damageColorChangeSpeed;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
originalColor = sprite.color;
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
health -= damage;
|
||||
StartCoroutine(DamageVisual());
|
||||
if (health <= 0)
|
||||
{
|
||||
thisEntity.OnDeath();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator DamageVisual()
|
||||
{
|
||||
float currentState = 0;
|
||||
while (currentState < 1)
|
||||
{
|
||||
currentState += Time.deltaTime * damageColorChangeSpeed;
|
||||
sprite.color = Color.Lerp(Color.gray, originalColor, currentState);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal(float healing)
|
||||
{
|
||||
health += healing;
|
||||
health = Math.Clamp(health, 0, maxHealth);
|
||||
}
|
||||
public bool OnGround()
|
||||
{
|
||||
return Physics2D.OverlapCircle(groundCheck.position, 0.05f, groundLayer);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue