- Home /
Cancelling any other button press
Hey, so im working on a pause script for my c sharp program and I managed to get it to work, however im looking for a way to also cancel other button presses located in other scripts, because even though my charater is paused, the other scripts are still working (if it helps: the buttons i need to cancel are z and x) heres my current script
using UnityEngine; using System.Collections;
public class Pause : MonoBehaviour { public bool paused = false; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.P)){
paused = !paused; //toggles between paused and not paused
}
if(paused){
Time.timeScale = 0;
}
else { Time.timeScale = 1; }
}
}
Answer by Mmmpies · Feb 23, 2015 at 04:43 PM
just make that paused bool public and only check for the key presses if the PauseScript paused bool is false. So in that other script reference the PauseScript, this assumes you hold the Pause script on the player and it's called PauseScript:
private PauseScript myPauseScript;
void Start(){
myPauseScript = GameObject.Find("Player").GetComponent<PauseScript>();
}
void Update(){
if(!myPauseScript.paused)
{
//check for keypress
}
Your answer
Follow this Question
Related Questions
Pause code wont work 2 Answers
How to pause game. 3 Answers
Zelda like pause menu 1 Answer
Setting up a menu system and pause screen 1 Answer
How do I pause a method? 1 Answer