Using a list of gameobjects to make GUIbuttons including images.
Hello I am trying to make an RTS type thing where GUItext buttons allow you to select certain buildings which you can then drag out and make.
I tried to make a list of GameObjects which had scripts on them with references to respective 2d texture images and something i called "ghost" which was going to be a translucent blueprint placeholder while the player worked out where he was placing the real deal.
This is my script;
public class blockplacementmanager : MonoBehaviour {
public GameObject[] unitList;
public GameObject ghost;
public GUIStyle icon;
void OnGUI ()
{
if (unitList.Length > 0)
{
for (int i = 0; i < unitList.Length; i++)
{
GameObject ghost = unitList [i].GetComponent<blockUnitScript> ().ghostObject as GameObject;
Texture2D icontex = unitList
[i].GetComponent ().menuicon;
GUIStyle icon = new GUIStyle();
icon.normal.background = icontex;
if (GUI.Button (new Rect (Screen.width / 20, Screen.height / 15 + i, 30, 30), "", icon))
{
//do something
}
}
}
}
}
The ghost gameobjects are being collated but I cannot actually make the buttons because I think the 2d images are not becoming GUIstyles to make the GUItext buttons with.
How much of a bodge-up is this and do people have any ideas how i might do this better?