Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class AudioController : MonoBehaviour {
- public AudioSource[] sound;
- public AudioSource steps;
- public AudioSource guns;
- public AudioClip[] concrete;
- public AudioClip[] dirt;
- public AudioClip gun1;
- public AudioClip reloadGun1;
- public AudioClip russianSong;
- private bool isMoving;
- [SerializeField]
- private float stepRate;
- private string floortag;
- private bool step;
- private bool playingStep;
- public AudioSync audioSync;
- public TauntController tauntController;
- public GravityFPSWalker controller;
- public AudioListener playerAudioListener;
- void Start()
- {
- tauntController = GetComponent<TauntController>();
- controller = GetComponent<GravityFPSWalker>();
- sound = GetComponents<AudioSource>();
- playerAudioListener = GetComponent<AudioListener>();
- audioSync = GetComponent<AudioSync>();
- steps = sound[0];
- guns = sound[1];
- guns.clip = gun1;
- isMoving = false;
- }
- void Update()
- {
- if (Input.GetButton("Horizontal") || Input.GetButton("Vertical"))
- {
- isMoving = true;
- }
- else
- {
- isMoving = false;
- }
- }
- void FixedUpdate()
- {
- RaycastHit hit;
- if (controller.grounded == true)
- {
- CalculateSound();
- if (Physics.Raycast(transform.position, Vector3.down, out hit))
- {
- floortag = hit.collider.gameObject.tag;
- }
- }
- }
- //Determines whether to play footsteps or not
- void CalculateSound()
- {
- if (Input.GetButtonDown("Horizontal") || Input.GetButtonDown("Vertical"))
- {
- if (tauntController.russianDance == false && playingStep == false)
- {
- InvokeRepeating("playStep", 0f, stepRate);
- }
- }
- if (isMoving == false)
- {
- CancelInvoke("playStep");
- playingStep = false;
- }
- }
- //Plays foostep sounds to the local client
- void playStep()
- {
- if (controller.grounded == true)
- {
- playingStep = true;
- if (floortag == "dirt")
- {
- steps.clip = dirt[Random.Range(0, dirt.Length)];
- }
- if (floortag == "concrete")
- {
- steps.clip = concrete[Random.Range(0, concrete.Length)];
- }
- Debug.Log("Played " + floortag);
- steps.Play();
- }
- }
- public void playTauntSong()
- {
- if (tauntController.russianDance == true)
- {
- playerAudioListener.enabled = true;
- steps.clip = russianSong;
- steps.loop = true;
- steps.Play();
- Debug.Log("Playing Kazotsky Kick");
- }
- }
- public void stopTauntSong()
- {
- playerAudioListener.enabled = false;
- steps.Stop();
- steps.loop = false;
- steps.clip = null;
- Debug.Log("Pausing Taunt Song");
- }
- public void playGunShots()
- {
- guns.PlayOneShot(gun1);
- Debug.Log("Bang!");
- }
- public void playReload()
- {
- guns.PlayOneShot(reloadGun1);
- Debug.Log("Played Reloaded");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement