Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Animal : MonoBehaviour
- {
- public string animalName;
- public bool playerInRange;
- [SerializeField] int currentHealth;
- [SerializeField] int maxHealth;
- [Header("Sounds")]
- [SerializeField] AudioSource soundChannel;
- [SerializeField] AudioClip rabbitHitAndDie, bearHitAndDie, foxHitAndDie, goatHitAndDie, sheepHitAndDie, wolfHitAndDie;
- [SerializeField] AudioClip rabbitHitAndScream, bearHitAndScream, foxHitAndScream, goatHitAndScream, sheepHitAndScream, wolfHitAndScream;
- private Animator animator;
- public bool isDead;
- [SerializeField] ParticleSystem bloodSplashParticles;
- public GameObject bloodPuddle;
- enum AnimalType
- {
- Rabbit,
- Bear,
- Fox, Goat, Sheep, Wolf
- }
- [SerializeField] AnimalType thisAnimalType;
- private void Start()
- {
- currentHealth = maxHealth;
- animator = GetComponent<Animator>();
- }
- public void TakeDamage(int damage)
- {
- if (isDead == false)
- {
- currentHealth -= damage;
- bloodSplashParticles.Play();
- if (currentHealth <= 0)
- {
- PlayDyingSound();
- animator.SetTrigger("DIE");
- GetComponent<AI_Movement>().enabled = false;
- StartCoroutine(PuddleDelay());
- isDead = true;
- }
- else
- {
- PlayHitSound();
- }
- }
- }
- IEnumerator PuddleDelay()
- {
- yield return new WaitForSeconds(1f);
- bloodPuddle.SetActive(true);
- }
- private void PlayDyingSound()
- {
- switch (thisAnimalType)
- {
- case AnimalType.Rabbit:
- soundChannel.PlayOneShot(rabbitHitAndDie); //Rabbit clip
- break;
- case AnimalType.Bear:
- soundChannel.PlayOneShot(bearHitAndDie); //Bear clip
- break;
- case AnimalType.Fox:
- soundChannel.PlayOneShot(foxHitAndDie); //Fox clip
- break;
- case AnimalType.Goat:
- soundChannel.PlayOneShot(goatHitAndDie); //Goat clip
- break;
- case AnimalType.Sheep:
- soundChannel.PlayOneShot(sheepHitAndDie); //Sheep clip
- break;
- case AnimalType.Wolf:
- soundChannel.PlayOneShot(wolfHitAndDie); //Wolf clip
- break;
- default:
- break;
- }
- }
- private void PlayHitSound()
- {
- switch (thisAnimalType)
- {
- case AnimalType.Rabbit:
- soundChannel.PlayOneShot(rabbitHitAndScream); //Rabbit clip
- break;
- case AnimalType.Bear:
- soundChannel.PlayOneShot(bearHitAndScream); //Bear clip
- break;
- case AnimalType.Fox:
- soundChannel.PlayOneShot(foxHitAndScream); //Fox clip
- break;
- case AnimalType.Goat:
- soundChannel.PlayOneShot(goatHitAndScream); //Goat clip
- break;
- case AnimalType.Sheep:
- soundChannel.PlayOneShot(sheepHitAndScream); //Sheep clip
- break;
- case AnimalType.Wolf:
- soundChannel.PlayOneShot(wolfHitAndScream); //Wolf clip
- break;
- default:
- break;
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Player"))
- {
- playerInRange = true;
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.CompareTag("Player"))
- {
- playerInRange = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement