- Home /
Question by
bobscorporation · Aug 02, 2013 at 07:54 AM ·
gameobjectinstancelinkpass
How can I pass an instance of a gameobject to another before runtime?
For example, I would like a lever to open a door. The issue is that there can be multiple levers that open different doors. How would I go about linking specific levers to specific doors in the editor, so that a script component on the lever can tell the door it is linked to to open?
Comment
Answer by DaveA · Aug 02, 2013 at 07:56 AM
Let's say you have a script called Lever, and a script called Door, each on respective objects. You can declare a variable like this in Lever:
var door : Door; // assign this in the Inspector
Assuming your scripts compile ok, in the inspector for your lever (you made it a Prefab, right?) you'll see a variable Door. Just drag a Door instance from your Scene onto that.
Your answer
