- Home /
GUIs for Power ups? No idea.
Hi, I'm having trouble with coding for a HUD. So, what I'm trying to do is make it so when a power up is picked up, it shows a little decal in the bottom right corner of the screen, and then, when you use the power up (by pressing the number that corresponds), the little decal goes away.
Here's the script that controls the powerups:
var hasPowerup:boolean = false; //variable that checks if the player has picked up the powerup
function Update()
{
transform.Rotate(Vector3.up * Time.deltaTime * 30); //slowly rotate the powerup object
if(hasPowerup == true)
{
/*
Activates GUI for power up, in bottom right
*/
Debug.Log("Powerup Obtained");
if(Input.GetKeyDown("1"))
{
Debug.Log("RATE!");
Power();
hasPowerup = false;
/*
Remove GUI for power up
*/
}
}
}
function OnTriggerEnter(obtainPowerup : Collider) //Detects collision between the player and the powerup object, and sets hasPowerup to true
{
if(obtainPowerup.gameObject.tag == "Player")
{
hasPowerup = true;
transform.position = Vector3(0,0,0);
}
}
function Power()
{
Fire.rate = Fire.rate / 2; //Doubles the rate of fire
Debug.Log("/2");
yield WaitForSeconds(8); //Waits for 8 seconds
Fire.rate = Fire.rate * 2; //Sets the rate of fire back to normal
Debug.Log("*2");
}
Kind of a long code... But yeah, how do I do this?
Answer by fherbst · Sep 08, 2013 at 08:03 AM
function OnGUI() {
if(!hasPowerup) return;
// draw your powerup, see the docs for OnGUI stuff
}
You will need some handling logic for your list of powerups, too. A second script which maintains a list of all picked powerups and tells them which key has to be pressed and in which order the GUI of them has to be drawn.
Your answer
Follow this Question
Related Questions
Cameras Switch Based On Button Click 1 Answer
creation of buttons and other gui stuffs 1 Answer
[SOLVED] HUD ammo counter showing up only when a bullet is fired 0 Answers
Render Sprite on Screen at 3d game 0 Answers
A GUI menu solution 0 Answers