Skip to content

Instantly share code, notes, and snippets.

@PappaBjorn
Created February 4, 2020 12:42
Show Gist options
  • Save PappaBjorn/c6e4ee24b0c5ecefb416d1759c2dfbbb to your computer and use it in GitHub Desktop.
Save PappaBjorn/c6e4ee24b0c5ecefb416d1759c2dfbbb to your computer and use it in GitHub Desktop.
Animation- and Sound handlers for Owlchemist
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioComponentChickenAI : MonoBehaviour
{
public AudioClip[] walkingSounds;
public AudioClip stalkingSound;
public AudioClip runningSound;
public AudioClip lookaroundSound;
public AudioClip[] staggerSound;
public AudioClip stompSound;
int voiceNumber;
public AudioSource audioS;
private void Start()
{
voiceNumber = Random.Range(0,1);
}
void WalkingSound()
{
audioS.PlayOneShot(walkingSounds[Random.Range(0, walkingSounds.Length - 1)]);
}
void StalkingSound()
{
//audioS.PlayOneShot(walkingSounds[Random.Range(0, walkingSounds.Length - 1)]);
audioS.PlayOneShot(stalkingSound);
}
void RunningSound()
{
audioS.PlayOneShot(runningSound);
}
void LookAroundSound()
{
audioS.PlayOneShot(lookaroundSound);
}
void StaggerSound()
{
audioS.PlayOneShot(staggerSound[voiceNumber]);
}
void StompSound()
{
audioS.PlayOneShot(stompSound);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
public class ChickenAnimations : MonoBehaviour
{
private Animator anim;
private ChickenAIComponent chickAI;
private void Awake()
{
anim = GetComponentInChildren<Animator>();
chickAI = GetComponent<ChickenAIComponent>();
chickAI.OnTriggerLook += TriggerLookAroundAnim;
chickAI.OnTriggerStagger += TriggerStaggerAnim;
chickAI.OnTriggerStomp += TriggerStompAnim;
chickAI.OnSetRunning += SetIsRunning;
chickAI.OnSetWalking += SetIsWalking;
chickAI.OnSetStalking += SetIsStalking;
Assert.IsNotNull(anim, "Animator is missing on Enemy");
}
private void TriggerLookAroundAnim()
{
anim.SetTrigger("LookAround");
}
private void TriggerStaggerAnim()
{
anim.SetTrigger("Stagger");
}
private void TriggerStompAnim()
{
anim.SetTrigger("Stomp");
}
private void SetIsRunning()
{
anim.SetBool("IsRunning", true);
anim.SetBool("IsWalking", false);
anim.SetBool("IsStalking", false);
}
private void SetIsWalking()
{
anim.SetBool("IsRunning", false);
anim.SetBool("IsWalking", true);
anim.SetBool("IsStalking", false);
}
private void SetIsStalking()
{
anim.SetBool("IsRunning", false);
anim.SetBool("IsWalking", false);
anim.SetBool("IsStalking", true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment