Quantcast
Channel: Questions in topic: "die"
Viewing all articles
Browse latest Browse all 115

player death sound not playing

$
0
0
i got my hurt sound to work when ever i come into contact with a spike but am not really sure why my death sound is not working public class playerHealth : MonoBehaviour { // declareing health variables public float maxHealth; private float currentHealth; // declareing audio variables public AudioClip playerDieing; public AudioClip[] hurt; public GameObject deathFX; // delcareing component variables private playerController controllerMovement; public AudioSource playerAS; // declareing hud variables public Image healthSlider; public Image damageScreen; private Color damagedColor = new Color(255f, 255f, 255f, 0.5f); private bool damaged = false; private float smoothColor = 5f; void Start () { // health instalization currentHealth = maxHealth; // component instalization controllerMovement = GetComponent(); playerAS = GetComponent(); // hud instalization healthSlider.fillAmount = maxHealth; damaged = false; } // Update is called once per frame void Update () { // if player is damaged then show the damage screen else make the damage screen disapper adjusting the alpha using lerp and deltatime if(damaged) { damageScreen.color = damagedColor; } else { damageScreen.color = Color.Lerp(damageScreen.color, Color.clear, smoothColor * Time.deltaTime); } // setting damaged equal to false damaged = false; } // controls if the player is being damaged if so then how much damage and what happens when the player takes damage public void addDamge(float damage) { if(damage <= 0) { return; } currentHealth -= damage; playerAS.PlayOneShot(hurt[Random.Range(0,hurt.Length)]); healthSlider.fillAmount = currentHealth / 100; damaged = true; if(currentHealth <= 0) { playerAS.PlayOneShot(playerDieing); makeDead(); } } public void makeDead() { Instantiate(deathFX, controllerMovement.transform.position, transform.rotation); Destroy(gameObject); } }

Viewing all articles
Browse latest Browse all 115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>