Skip to content

Instantly share code, notes, and snippets.

@JCaraballo113
Created February 23, 2019 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JCaraballo113/1e864f1cc877300f7c9fdf87863b2cf9 to your computer and use it in GitHub Desktop.
Save JCaraballo113/1e864f1cc877300f7c9fdf87863b2cf9 to your computer and use it in GitHub Desktop.
public class Enemy : MonoBehaviour, IDamageable
{
[Header("General")]
[SerializeField] EnemyType enemyType = EnemyType.Light;
[SerializeField] Transform parent;
[Header("Effects")]
[SerializeField] GameObject explosionFX;
[SerializeField] GameObject hitFX;
HealthSystem healthSystem;
ScoreBoard scoreBoard;
void Start()
{
gameObject.AddComponent<BoxCollider>();
scoreBoard = FindObjectOfType<ScoreBoard>();
healthSystem = GetComponent<HealthSystem>();
}
int GetDamageByType()
{
switch(enemyType)
{
case EnemyType.Light:
return 20;
case EnemyType.Medium:
return 15;
case EnemyType.Heavy:
return 10;
default:
return 0;
}
}
private void OnParticleCollision(GameObject other)
{
TakeDamage();
}
public void TakeDamage()
{
scoreBoard.ScoreHit(enemyType);
healthSystem.Damage(GetDamageByType());
GameObject instance = Instantiate(hitFX, transform.position, Quaternion.identity);
instance.transform.parent = parent;
if (healthSystem.GetCurrentHealth() <= 0)
{
Kill();
}
}
private void Kill()
{
GameObject instance = Instantiate(explosionFX, transform.position, Quaternion.identity);
instance.transform.parent = parent;
Destroy(gameObject);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment