- Home /
what do i write here
where you would normally have var something : GameObject; what would you put instead of GameObject when something is a script?
Answer by DaveA · Nov 09, 2011 at 07:46 AM
If I understand you correctly, you could use Component but more likely use the name of the script.
If you have a script called 'OtherScript':
var other : OtherScript;
ok theres no errors now but it wont let me put my script on to the OtherScript spot on the inspector ins$$anonymous$$d it lets me put objects there
Of course, you can't assign "script files" to a variable, only instances of this script which have to be attached to a GameObject. The script is just the class (a blueprint for your component). You have to attach your "OtherScript" to a GameObject and then drag the instance onto your variable.
Either by dragging the GameObject onto the variable (Unity will take the right Component if there is one) or by using two inspector windows (one is locked) and then drag the Component itself (grab it at it's title-bar-foldout) onto the variable.
Answer by kridesu · Nov 10, 2011 at 10:08 AM
Also, sometimes you are better off finding this game object as opposed to manually dragging it to where you want the reference and then just getting the component. E.g., you could say:
function Awake()
{
var myGameObject = GameObject.Find("MyGameObject");
someVariable = myGameObject.GetComponent(ScriptYouWant);
}