Unity: Assigning String value in inspector
Posted
by
Marc Pilgaard
on Game Development
See other posts from Game Development
or by Marc Pilgaard
Published on 2011-11-22T13:03:19Z
Indexed on
2011/11/22
18:17 UTC
Read the original article
Hit count: 253
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
© Game Development or respective owner