Created
December 19, 2017 10:08
-
-
Save Curookie/b18a7870a64135f9bd6775c8f8dc6e95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class EnemyHPCtrl : MonoBehaviour { | |
public int startingHealth = 100; | |
public int currentHealth; | |
public float sinkSpeed = 2.5f; | |
public int scoreValue = 10; | |
public AudioClip deathClip; | |
Animator anim; | |
AudioSource enemyAudio; | |
ParticleSystem hitParticles; | |
CapsuleCollider capsuleCollider; | |
bool isDead; | |
bool isSinking; | |
void Awake() | |
{ | |
anim = GetComponent<Animator>(); | |
enemyAudio = GetComponent<AudioSource>(); | |
hitParticles = GetComponentInChildren<ParticleSystem>(); | |
capsuleCollider = GetComponent<CapsuleCollider>(); | |
currentHealth = startingHealth; | |
} | |
void Update() | |
{ | |
if (isSinking) | |
{ | |
transform.Translate(-Vector3.up * sinkSpeed * Time.deltaTime); | |
} | |
} | |
public void TakeDamage(int amount, Vector3 hitPoint) | |
{ | |
if (isDead) | |
return; | |
enemyAudio.Play(); | |
currentHealth -= amount; | |
hitParticles.transform.position = hitPoint; | |
hitParticles.Play(); | |
if (currentHealth <= 0) | |
{ | |
Death(); | |
} | |
} | |
void Death() | |
{ | |
isDead = true; | |
capsuleCollider.isTrigger = true; | |
anim.SetTrigger("Dead"); | |
enemyAudio.clip = deathClip; | |
enemyAudio.Play(); | |
} | |
public void StartSinking() | |
{ | |
GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = false; | |
GetComponent<Rigidbody>().isKinematic = true; | |
isSinking = true; | |
//ScoreManager.score += scoreValue; | |
Destroy(gameObject, 2f); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment