Hi all,
How do I disable script and functions from that script within code.
I've used
var script : thescript;
thescript.enabled = false;
This results in the script being disabled but the functions still work.
How do I disable or disconnect that script so that it completely turns off and does not
affect the game?
Behavior.enabled, which MonoBehavior.enabled is inherited from, only switches the calling of Update() on/off, as was previously commented, and as per the documentation:
Note that MonoBehavior is a class, of which an object is instantiated; you can't disconnect it entirely in the sense that it disables the ability to call those of its methods you yourself defined.
If you want to do that, you can either check to see whether the script is enabled before your code calls one of its methods yourself, or you can enclose the content of your methods inside the script in if(this.enabled) {}.
When you disable a component that, it' just stop doing the codein Update and stuff like that, but I think it doesn't disabled your own functions. I'm not sure your can do that, maybe try scrit.gameObject.active = false;
public GameObject otherobj;//your other object
public string scr;// your secound script name
void Start () {
(otherobj. GetComponent(scr) as MonoBehaviour).enabled = false;
}