- Home /
InGame Menu (toggle)
Hey guys, using C# to make an ingame Menu which'll toggle on and off.
Using the blur screen Image effect for once I hit escape and too disable once Escape is pressed again.
here is my script;
using UnityEngine;
using System.Collections;
public class IngameMenu : MonoBehaviour { bool paused = false;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
togglePause();
}
void OnGUI()
{
//boop
}
void togglePause()
{
if (paused)
{
Time.timeScale = 1f;
paused = false;
}
else
{
Time.timeScale = 0f;
paused = true;
}
}
}
I was wondering if it were possible to actually disable/enable to script or communicate to it via the code, I'm not too sure how to do it.
Answer by Fabkins · Nov 01, 2011 at 11:13 PM
Ok, I know how to do this in JS and I suspect its the same for C#
All you would need is create a static function. So it could be something like:
var stat: boolean = true; // default enabled
static function disableTogglePause( in)
{
stat =in;
}
void togglePause()
{
if(stat)
{
// whatever you used to do.
}
}
You can call this anywhere in the code by using the class name and the method. ie
myClassname.disableTogglePause(false);
Answer by mrapple · Nov 02, 2011 at 12:39 AM
It looks sort of the same, but I don't really understand JavaScript.
Your answer
Follow this Question
Related Questions
Neutral state for toggle buttons? 2 Answers
GUI window popup button 1 Answer
Blurry Texture Help 5 Answers
Little help with GUI Toggle needed 1 Answer
GUI Button selected changes color and stays until another button is clicked 1 Answer