- Home /
The question is answered, right answer was accepted
How to Instantiate from correct Icon.
This related to my previous question.http: //answers.unity3d.com/questions/533360/how-to-link-string-to-gameobjectprefab-to-load-fro.html
So I got the correct Prefab GameObject to be linked to the correct Icon and name but now I can't figure out how to get the GUI to instantiate the linked object when clicking the icon.
So CreateTurret("TurretName"); This instantiates and works but I have to name it manually.
What I need is CreateTurret(name of icon and button clicked);
This is what I mean:
// This is the part where the GUI with the buttons and icons of the turrets are set and where the object is supposed to be instantiated using the function in the previous question. IE: CreateTurret(string name);
//selectUIScript[cnt].Cameo is the Icon that I need to tell CreateTurret() to get by name... so when I click it creates the turret for that icon.
if(GUI.Button(new Rect(selectbuttonWidth * cnt, 30, selectbuttonWidth, selectbuttonHeight), new GUIContent(selectUIScript.baseList[cnt].Cameo, selectUIScript.baseList[cnt].ToolTipVehicle()))){
constuctorScript.CreateTurret();
}
// So basically what do I have to type in the brackets of CreateTurret() in order to instantiate by the name of the Icon which is linked to the prefab?
Lol holy crap, I had tried all kinds of stuff but didn't try that. The same thing was right above the dam CreateTurret but for the Cameo.
$$anonymous$$an you guys are very useful.
Thanks man.
Not closing this question yet though because I have one more last issue that I might not be able to solve regarding this.
Alright never $$anonymous$$d the other issue I sorted it.
Thanks again.
Answer by ArkaneX · Sep 10, 2013 at 12:40 PM
Basing on the previous question - is selectUIScript.baseList
a list of TurretClass? If yes, then you have to use:
constuctorScript.CreateTurret(selectUIScript.baseList[cnt].Name);
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Creating an Object with a string C#! How? 1 Answer
Distribute terrain in zones 3 Answers
How do you Instantiate a button as a child object of a canvas? 0 Answers