Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by rct3fan24 · Sep 08, 2013 at 02:02 AM · guihud

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges