- Home /
Question by
RevCosmosis · Jun 15, 2014 at 03:09 PM ·
inspectormonoscript
Specifying script through inspector
In my game, I have a system where a puzzle (managed by GridPuzzle.js) will open a door (managed by DoorScript01.js) when the puzzle is solved. The relevant code in GridPuzzle.js:
var targetDoor : GameObject;
...
...
if (puzzleIsSolved) {
targetDoor.GetComponent(DoorScript01).Open();
}
It works fine. However, in the future, I may end up with more than just one type of door - doors that run on DoorScript02, DoorScript03, and so on. I don't want to create a new GridPuzzle.js for each type of DoorScript, but I can't find a way to assign a script reference in the inspector. This was the best I could figure out:
var targetDoor : GameObject;
var targetDoorScript : String;
...
...
if (puzzleIsSolved) {
targetDoor.GetComponent(targetDoorScript).Open();
}
This gives the error 'Open' is not a member of 'UnityEngine.Component'. What can I do to be able to define a script name in the inspector?
Comment