45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class HauntedPhone : MonoBehaviour
|
||
|
|
{
|
||
|
|
public AudioSource phoneAudioSource;
|
||
|
|
public AudioClip ringSound;
|
||
|
|
|
||
|
|
private bool isRinging = false;
|
||
|
|
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
if(phoneAudioSource == null) phoneAudioSource = GetComponent<AudioSource>();
|
||
|
|
phoneAudioSource.loop = true; // Make sure the ringing loops!
|
||
|
|
}
|
||
|
|
|
||
|
|
// Call this from the LightSwitch "OnFirstSwitchOff"
|
||
|
|
public void StartRinging()
|
||
|
|
{
|
||
|
|
if (!isRinging && ringSound != null)
|
||
|
|
{
|
||
|
|
phoneAudioSource.clip = ringSound;
|
||
|
|
phoneAudioSource.Play();
|
||
|
|
isRinging = true;
|
||
|
|
Debug.Log("Phone started ringing...");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Call this from the LightSwitch "OnFirstSwitchOn"
|
||
|
|
public void StopRinging()
|
||
|
|
{
|
||
|
|
if (isRinging)
|
||
|
|
{
|
||
|
|
phoneAudioSource.Stop();
|
||
|
|
isRinging = false;
|
||
|
|
Debug.Log("Phone stopped.");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Call this from "OnRandomEvent" for a quick scare
|
||
|
|
public void PlayCreepyWhisper()
|
||
|
|
{
|
||
|
|
// Logic for a one-shot scare sound
|
||
|
|
Debug.Log("Creepy whisper played from phone...");
|
||
|
|
}
|
||
|
|
}
|