Created
May 14, 2019 05:16
-
-
Save SenpaiRar/d9cb9ac25b5355f8c3d468e9928b85cb to your computer and use it in GitHub Desktop.
This is the script for the zombie. For this section, I've cut out most of the script to only include the audio portions.
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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Enemy_Zombie : Entity_Parent { | |
//We create reference to the AudioSource that we can drag in because the zombies are a prefab | |
public AudioSource Source; | |
//This is the Audioclip of the zombie dying. Audio clips are made by downloading sounds from the internet and dragging them into the asset window | |
public AudioClip DieClip; | |
//This is the clip for a zombie snarling. It plays periodically. | |
public AudioClip SnarlClip; | |
//This is the time between the zombies snarling | |
public float AudioInterval; | |
void Start () { | |
StartCoroutine(PlayGrowl()); | |
} | |
// Update is called once per frame | |
void Update () { | |
CheckAttack(); | |
if(current_Health_Level <= 0) | |
{ | |
//PlayOneShot is a command from the AudioSource Component which lets us play any audio clip we feed into the function | |
Source.PlayOneShot(DieClip); | |
Die(); | |
} | |
} | |
//Here we define a coroutine that will use PlayOneShot to play the snarlclips every AudioInterval seconds with an addtional random range | |
IEnumerator PlayGrowl(){ | |
for(;;){ | |
Source.PlayOneShot(SnarlClip); | |
yield return new WaitForSeconds(AudioInterval + Random.Range(0, 10.0f)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment