- Home /
Disable Script
I have a inventory script. When i press B it pauses time "So i cant move" now on my main camera there is a Mouse Look script. How can i disable the script.
function Update(){
if ((Input.GetKeyDown (inventory.inventoryKey))&&(showSplitDiag==false)&&(shopScript.toogleShop==false)){
if(toogleInv == false){
toogleInv = true;
Screen.lockCursor = false;
Time.timeScale = 0;
}else{
selectedItem = false;
toogleInv = false;
}
}
This Script is actually attached to the main Camera so i think that would make it easier. Please reply in JS since i do not use/know C# at all.
Answer by CodeMasterMike · Feb 21, 2013 at 10:41 AM
You set the script enable to false. Something like this:
YourScriptToDisable currentScript = GetComponent(YourScriptToDisable);
if(currentScript != null)
{
currentScript.enabled = false;
}
When you want to re-enable it, you just set it to true again:
YourScriptToEnable currentScript = GetComponent(YourScriptToEnable);
if(currentScript != null)
{
currentScript.enabled = true;
}
Worth to mention: YourScriptToDisable/YourScriptToEnable, is the name of the script that you have. If you look in the MonoBehaviour documentation, you will also find functions and other things that might come in handy.
Good luck!
Its telling me to add a semicolon on line 173 - GetComponent($$anonymous$$ouseLook);
but as you can see there is one...
I don't really know javascript that well, so I can't tell really what your problem is. But look at the documentation (http://docs.unity3d.com/Documentation/ScriptReference/Behaviour-enabled.html?from=$$anonymous$$onoBehaviour), it shows you how to enable/disable the script.
Your answer
![](https://koobas.hobune.stream/wayback/20220613093117im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Cursor Lock to Center of screen script doesnt work please help. 2 Answers
Script to disable MouseLook? 2 Answers
How do I resize the image on a GUILayout? 1 Answer
Disable GameObject Only Father Not Children 2 Answers
Unity mathematics phrasing. 1 Answer