Unity: Assigning String value in inspector
- by Marc Pilgaard
I got an issue with Unity I can't seem to comprehend, and it is possibly very simple:
I am trying to write a simple piece of code in JavaScript where a button toggles the activation of a shield, by dragging a prefab with Resources.load("ActivateShieldPreFab") and destroying it again (Haven't implemented that yet).
I wish to assign this button through the inspector, so I have created a string variable which appears as intended in the inspector. Though it doesn't seem to register the inspector input, even though I changed the value through the inspector.
It only provides the error: "Input Key named: is unknown"
When the button name is assigned within the code, there is no issues.
Code as follows:
var ShieldOn = false;
var stringbutton : String;
function Start(){
}
function Update () {
if(Input.GetKey(stringbutton) && ShieldOn != true)
{
Instantiate(Resources.load("ActivateShieldPreFab"), Vector3 (0, 0, 0), Quaternion.identity);
ShieldOn = true;
}
}
Hope somebody can help, in advance... Thanks