Skip to content

Instantly share code, notes, and snippets.

@reidblomquist
Created June 22, 2015 05:55
Show Gist options
  • Save reidblomquist/c22687bf22238d46447a to your computer and use it in GitHub Desktop.
Save reidblomquist/c22687bf22238d46447a to your computer and use it in GitHub Desktop.
Loader and SoundManager scripts referenced in TextTyper class
using UnityEngine;
using System.Collections;
public class Loader : MonoBehaviour {
public GameObject gameManager;
public GameObject soundManager;
void Awake () {
if (gameManager && GameManager.instance == null)
Instantiate(gameManager);
if (soundManager && SoundManager.instance == null)
Instantiate(soundManager);
}
}
using UnityEngine;
using System.Collections;
public class SoundManager : MonoBehaviour {
public AudioSource efxSource;
public AudioSource musicSource;
public static SoundManager instance = null;
public float lowPitchRange = 0.95f;
public float highPitchRange = 1.05f;
void Awake () {
if (instance == null)
instance = this;
else if (instance != this)
Destroy (gameObject);
DontDestroyOnLoad (gameObject);
}
public void PlaySingle (AudioClip clip) {
efxSource.clip = clip;
efxSource.Play();
}
public void RandomizeSfx (params AudioClip [] clips) {
int randomIndex = Random.Range(0, clips.Length);
float randomPitch = Random.Range (lowPitchRange, highPitchRange);
efxSource.pitch = randomPitch;
efxSource.clip = clips[randomIndex];
efxSource.Play();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment