- Home /
script slot possible?
i alreddy looked arround but could not find a solution. this is just a wild gues of what it should be but i cant get it any better i just want to make some sort of script slot where i can drag a script into it. and than add the script to its gameobject trigger whare the other script alreddy is attached on so i want to every time i go in to the trigger area. i want to activate the script in the slot so my question would be is this possible to do? anyway thanks
var script : Script;
function OnTriggerEnter(other : Collider) { script.enabled = true; }
greatz wezz from the Netherlands
Answer by Uzquiano · Apr 24, 2011 at 02:43 PM
Yes ;)
Though I use this:
GameObject.Find("Main Camera").GetComponent(Camera).enabled = false;//I am switching off the camera of the Main Camera
Instead of 'Camera' you can put there the name of your script without "" or anything.
I posted the code for enabling/disabling components in general.
One advise, if you do Find(), do it at the very begining and keep the reference in a variable for later use.
Cheers
Answer by Justin Warner · Apr 24, 2011 at 02:46 PM
I think you're supposed to use the GetComponent command...
You can't really add in scripts like that...
If you want, you can actually put the whole script in there too?
But for GetComponent, you can add the actual script to the object, so you have 2 scripts attatched and use:
otherScript = GetComponent(OtherScript);
OtherScript being the name of the script you're trying to access.
If the script is on a different object, something like this'll work:
transform.Find("Hand").GetComponent(OtherScript).DoSomething("Hello");
You can read about more here: http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
Good luck =).
Your answer
![](https://koobas.hobune.stream/wayback/20220613124920im_/https://answers.unity.com/themes/thub/images/avi.jpg)