Created
February 23, 2019 17:59
-
-
Save JCaraballo113/1e864f1cc877300f7c9fdf87863b2cf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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