Skip to content

Instantly share code, notes, and snippets.

@feranmii
Last active May 14, 2019 22:47
Show Gist options
  • Save feranmii/2ef46eccef6cc5b5c2154da559b61e63 to your computer and use it in GitHub Desktop.
Save feranmii/2ef46eccef6cc5b5c2154da559b61e63 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class Actor : PhysicsObject, IDamage
{
[Header("Stats")]
[SerializeField] protected int jumpCount;
[SerializeField] private int health;
[SerializeField] protected float jumpTakeOffSpeed;
[Header("References")]
[SerializeField] private GameObject deathFx;
[SerializeField] private ParticleSystem jumpFx;
private Renderer _renderer;
private bool _facingRight;
protected virtual void Awake()
{
_facingRight = true;
jumpCount = 2;
health = 100;
_renderer = GetComponent<Renderer>();
}
protected void FlipActor(int dir)
{
if (_facingRight && dir < 0 || !_facingRight && dir > 0)
{
_facingRight = !_facingRight;
SpriteRenderer sprite = (SpriteRenderer) _renderer;
sprite.flipX = !sprite.flipX;
}
}
public virtual void Damage(int amount)
{
health -= amount;
if (health <= 0)
{
Die();
}
}
public void Jump()
{
if (jumpCount > 0)
{
velocity.y = jumpTakeOffSpeed;
jumpCount--;
if(jumpFx != null)
Instantiate(jumpFx, transform.position, Quaternion.identity);
}
}
protected override void ComputeVelocity()
{
}
public virtual void Die()
{
deathFx.SetActive(true);
deathFx.transform.parent = transform.parent;
Destroy(gameObject);
}
protected virtual void Fire()
{
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("BottomBounds"))
{
Die();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment