- Home /
turn .cs file on and off with keypress????
i have a pause script done in .CS i press escape it comes up but when i press escape it doesnt go away, what do i need to change in this script to turn it on and off with keypress
thanks heaps
void Update ()
{
if (_ingame && CurrentState != MainMenu && CurrentState != ErrorPrompt && Input.GetKeyDown(KeyCode.I))
{
CurrentState = MainMenu;
}
}
Would you $$anonymous$$d narrowing down to the relevant part? You give to much to read. If you give the 5 lines of your problem, you get an answer in 5 $$anonymous$$utes. If you give the whole script like you did. I walk away.
First of all you posted a lot of code. It would be better if you post the code only relevant to problem.
You must have posted the wrong script. There is no pause or mention of the esc key that I can see, but it's so much code I may have missed it.
Answer by Ashish Dwivedi · Feb 02, 2014 at 06:31 AM
Here is some sample code according to your requirement. I think this would help you...
using UnityEngine; using System.Collections;
public class GameManager : MonoBehaviour { Turn mTurn;
// Use this for initialization
void Start ()
{
mTurn = GameObject.Find("Turn").GetComponent<Turn>();
}
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
if(mTurn.enabled)
{
mTurn.enabled = false;
}
else
{
mTurn.enabled = true;
}
}
}
} `
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape))
{
mTurn.enabled = !mTurn.enabled;
}
Less code and you save the environment.
Your answer
![](https://koobas.hobune.stream/wayback/20220613132317im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUIUtility.DisplayCustomMenu().. how can I disable one of these menu items.. 3 Answers
I have been struggling with a GUI texture for over a week now. What am I doing wrong? 1 Answer
GUI not work after building 1 Answer
How to make a selection list using either GUI system? 0 Answers
changing from mouse click to keys 0 Answers