Files
Stair_Horror/Assets/Scripts/HauntedPram.cs

82 lines
2.2 KiB
C#
Raw Normal View History

using UnityEngine;
public class HauntedPram : MonoBehaviour
{
public AudioSource pramAudioSource, babyAudioSource;
public AudioClip creakSound, babyCrySound;
private bool isCreaking = false, isCrying = false;
void Start()
{
if(pramAudioSource == null) pramAudioSource = GetComponent<AudioSource>();
pramAudioSource.loop = true; // Make sure the creaking loops!
}
// Call this from the LightSwitch "OnFirstSwitchOff"
public void StartCreaking()
{
if (!isCreaking && creakSound != null)
{
pramAudioSource.clip = creakSound;
pramAudioSource.Play();
isCreaking = true;
Debug.Log("Pram started creaking...");
}
}
// Call this from the LightSwitch "OnFirstSwitchOn"
public void StopCreaking()
{
if (isCreaking)
{
pramAudioSource.Stop();
isCreaking = false;
Debug.Log("Pram stopped creaking.");
}
}
public void StartCrying()
{
if (!isCrying && babyCrySound != null)
{
pramAudioSource.clip = babyCrySound;
pramAudioSource.Play();
isCrying = true;
Debug.Log("Pram baby started crying...");
}
}
public void StopCrying()
{
if (isCrying)
{
pramAudioSource.Stop();
isCrying = false;
Debug.Log("Pram baby stopped crying.");
}
}
public void StartAllSounds()
{
if (!isCreaking && creakSound != null && !isCrying && babyCrySound != null)
{
pramAudioSource.clip = creakSound;
babyAudioSource.clip = babyCrySound;
pramAudioSource.Play();
babyAudioSource.Play();
isCreaking = true;
isCrying = true;
Debug.Log("Pram started creaking and crying...");
}
}
public void StopAllSounds()
{
if (isCreaking || isCrying)
{
pramAudioSource.Stop();
babyAudioSource.Stop();
isCreaking = false;
isCrying = false;
Debug.Log("Pram stopped all sounds.");
}
}
}