I´m trying to edit a script, wich allows the player to read a note upon pressing E. I made some changes, but i have a question: There´s a way to pause the game when player hit “E” to read the note, and unpause when hit “E” again?
Sorry for my bad english, i´m from Brazil.
Here´s the script i´m usging. Is attached to the player.
publicfloat maxDistance =1.5F;
publicGUISkin skin;
privatebool readingNote =false;
publicAudioClipNoteOpen;
publicAudioClipNoteClose;
voidStart(){
StartCoroutine(CheckForInput());
}
privateIEnumeratorCheckForInput(){
if(Input.GetKeyDown(KeyCode.F)){
if(!readingNote)
CheckForNote();
else{
readingNote =false;
audio.PlayOneShot(NoteClose);
}
}
yieldreturnnull;
}
}
privatevoidCheckForNote(){
Ray ray =Camera.main.ViewportPointToRay(newVector3(0.5F,0.5F,0));
Hey first of all I’d like to point you to the “Using code tags properly” thread which shows you how to nicely format code here in the boards:
About the problem - the usual way to do any pausing would be to set the Time.timeScale to a very low factor like 0.000001f. Don’t set it to 0 though since that has turned out to break stuff here and there. The low value is just as good.
When E is hit again, just set it back to 1. Something like this which will toggle the timeScale:
Just put Time.timeScale = 0.000001f next to your “readingNote = true;” statement, meaning once you set to read a note. Because that’s where you actually want to pause the game, don’t you?
Reset the Time.timeScale back to 1 next to setting “readingNote = false;”