I want to create an audio containment script which disables first person controls during the playing of an audio file attached to a reader object.
I’m in game audio class, and I have audio files in triggered objects I want to have the player listen all the way through before they can click out of them
Scenario:
FPP picks up a letter, with a reader. script is set so that you click E to open, and right click to close out
Problem:
There is nothing to prevent player from clicking out of reader before audio is completed.
Please feel free to ask questions and I’ll answer as best I can
using UnityEngine;
using System.Collections;
public class Letter : MonoBehaviour {
public AudioClip ExamineSFX;
public float SFX_Volume;
public AudioClip ExamineVOX;
public float VOX_Volume;
private AudioSource Audio;
private float SMX;
private float SMY;
private MouseLook CamSens;
public GameObject Reader;
private Examiner Pause;
private GameObject UI;
private bool LiveLetter = false;
void Start () {
Audio = gameObject.GetComponent<AudioSource> ();
CamSens = GameObject.Find ("First Person Controller").GetComponent<MouseLook> ();
Pause = GameObject.Find ("Main Camera").GetComponent<Examiner> ();
}
void Update(){
if (Pause.Paused && Input.GetButtonDown("Fire1") && LiveLetter){
CamSens.sensitivityX = SMX;
CamSens.sensitivityY = SMY;
Time.timeScale = 1;
GameObject.Destroy(UI);
Cursor.visible = false;
Pause.Paused = false;
LiveLetter = false;
Audio.Stop ();
Audio.PlayOneShot(ExamineVOX,VOX_Volume);
}
}
void Examine(){
SMX = CamSens.sensitivityX;
CamSens.sensitivityX = 0f;
SMY = CamSens.sensitivityY;
CamSens.sensitivityY = 0f;
UI = Instantiate (Reader);
Time.timeScale = 0;
Cursor.visible = true;
Pause.Paused = true;
LiveLetter = true;
Audio.Stop ();
Audio.PlayOneShot (ExamineSFX, SFX_Volume);
}
}
this is the code for the object (letter that First Person picks up and reads)