- Home /
Need to make a searching tool that can find gameObjects that contain the word the user inputs
Its a noob question. Right now I am getting an error: 'name' is not a member of Object. Any help appreciated!!!
GUI.BeginGroup (new Rect (Screen.width - 250,Screen.height - 30, Screen.width,Screen.height));
GUI.Box (new Rect (0,0,250,30),"");
GUI.Label (Rect (10, 5, 100, 20), "Find:");
var stringToEdit : String = "Enter part";
stringToEdit = GUI.TextField (Rect (50, 5, 150, 20), stringToEdit, 30);
if (GUI.Button(Rect(205,5,35,20),btnTexture)){
searchVariable = GameObject.Find(stringToEdit);
var searchedVariables = new Array();
for (var obj : GameObject in objects) {
if (obj.name.Contains(stringToEdit)) {
searchedVariables.Add(obj);
}
for (var i : int = 0; i < searchedVariables.length; i++)
{
if (searchedVariables[i].name.Contains(stringToEdit))
{
GUI.Label(searchedVariables[i].name);
}
}
}
Comment
Best Answer
Answer by Graham-Dunnett · Jun 09, 2014 at 03:43 PM
When coding in Javascript it is strongly recommended that you use typing. Although the Javascript runtime can do duck-typing it's not recommended. So you should define searchedVariables
to be an array of game objects.
Your answer
