- Home /
Question by
valtteri_m · Sep 21, 2014 at 07:50 AM ·
c#javascriptdisableenable
Disable C# Script from Java Script
I have this code that once the player gets near a spawner point is disables a script that spawns the mobs, problem is that I dont know how to disable c# scripts from java.
var player : Transform;
var distance = 3;
var CloseEnough : boolean = false;
//Var Script
function Update(){
if(Vector2.Distance(transform.position, player.position) < distance){
CloseEnough = true;
//Disable Script
}
else{
CloseEnough = false;
//Enable Script
}
}
Comment
Best Answer
Wiki
Answer by nooneknows · Sep 21, 2014 at 10:44 AM
Gameobject obj = Gameobject.find("name of the object owning the c# script");//finding //the object of the script
Monobehaviour mono = obj.getComponent();//getting the script
mono.enabled = false; /or/ mono.enabled = true; This works like disabling a unityscript script, but you have to respect the order of compilation: http://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html