- Home /
How can I create an RTS style build function into my GUI
Hello,
I have set up a GUI in my game in that when I select a building slot a GUI pops up, I can then click on the building I want and it builds there. What I would like is that when you click it displays a timer in a transparent colour wheel, much like many command and conquer type games, then when finished show some text to say ready, allow me to click the button and then instantiate into the scene. I use a texture "_Cutout" effect for my health bars, could I use the same thing or is there a better way? I am also looking at having it enter a ready texture when finished so the user can then just click to deploy if that be done the same way.
Heres some of my code;
//GUI
void OnGUI()
{
//TURRET GUI BAR
//---------------------------------------------------------------------------------------------------------------------------
GUI.Box (new Rect (Screen.width - 200,0,200,200), "miniMap");
if(TurretMenuOpen == true)
{
GUI.Box (new Rect (Screen.width - 600,Screen.height - 120,600,120), "BuildMenu");
if(GUI.Button (new Rect (Screen.width - 300,Screen.height - 100,100,100), Inf_Gun, guiStyle))
{
Debug.Log("Clicked the button with INF");
//clicked button
if(Input.GetMouseButtonUp(0))
{
if(SelectedObj.tag == "Placement_Open")
{
GameObject NewTurret = Instantiate (buildings[0], SelectedObj.transform.position, SelectedObj.transform.rotation) as GameObject;
audio.PlayOneShot(a_Building);
SelectedObj.tag = "Placement_Closed";
} else {
audio.PlayOneShot(a_CantDeploy);
}
}
}
if(GUI.Button (new Rect (Screen.width - 400,Screen.height - 100,100,100), Tank_Gun, guiStyle))
{
Debug.Log("Clicked the button with TANK");
if(Input.GetMouseButtonUp(0))
{
if(SelectedObj.tag == "Placement_Open")
{
GameObject NewTurret = Instantiate (buildings[1], SelectedObj.transform.position, SelectedObj.transform.rotation) as GameObject;
audio.PlayOneShot(a_Building);
SelectedObj.tag = "Placement_Closed";
}else {
audio.PlayOneShot(a_CantDeploy);
}
}
}
if(GUI.Button (new Rect (Screen.width - 500,Screen.height - 100,100,100), Air_Gun, guiStyle))
{
Debug.Log("Clicked the button with AIR");
if(Input.GetMouseButtonUp(0))
{
if(SelectedObj.tag == "Placement_Open")
{
GUI.DrawTexture(new Rect (Screen.width - 500,Screen.height - 100,100,100 * progressAmount), progressBar);
GameObject NewTurret = Instantiate (buildings[2], SelectedObj.transform.position, SelectedObj.transform.rotation) as GameObject;
audio.PlayOneShot(a_Building);
SelectedObj.tag = "Placement_Closed";
}else {
audio.PlayOneShot(a_CantDeploy);
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------------
}
I tried to get the effect using GUI.texture but nothing happened, I deleted it but I'll retype something along the same lines;
void OnGUI()
{
//TURRET GUI BAR
//---------------------------------------------------------------------------------------------------------------------------
GUI.Box (new Rect (Screen.width - 200,0,200,200), "miniMap");
if(TurretMenuOpen == true)
{
GUI.Box (new Rect (Screen.width - 600,Screen.height - 120,600,120), "BuildMenu");
if(GUI.Button (new Rect (Screen.width - 300,Screen.height - 100,100,100), Inf_Gun, guiStyle))
{
Debug.Log("Clicked the button with INF");
//clicked button
if(Input.GetMouseButtonUp(0))
{
if(!coolDown)
{
coolDown = true;
startTime = Time.time;
}
else
{
GUI.DrawTexture(new Rect(Screen.width - 300, Screen.height - 100,100,100 * coolDownTimer() ), coolDownTex); //Texture that is applied over top
}
if(Input.GetMouseButtonUp(0))
{
if(SelectedObj.tag == "Placement_Open")
{
GameObject NewTurret = Instantiate (buildings[0], SelectedObj.transform.position, SelectedObj.transform.rotation) as GameObject;
audio.PlayOneShot(a_Building);
SelectedObj.tag = "Placement_Closed";
} else {
audio.PlayOneShot(a_CantDeploy);
}
}
}
}
}
Helper function and parameters;
public float coolDownTimer()
{
float coolDownPercent = 0.5f;
if(coolDownPercent <=0)
coolDown = false;
return coolDownPercent;
}
public bool coolDown;
public float startTime;
public Texture coolDownTex;
public Texture buildingReadyTexture;
I've not been coding long so apologies if this is sacrilege to all you programmers out there,
Thanks in advance,
Steve.