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 BlackBoy0 · Feb 05, 2011 at 02:56 AM · 2donguihealth

Questions about GUI?

So I am trying to create a GUI for when the player dies (Losing health, falling off the map, etc.). Here is my code:

function OnDeath() { // Lose Health on Death health--;

// Reload entire level if (health != 0) { Spawn(); } else if (health == 0) { Destroy(gameObject); print("You have died."); } // Lose Score on Death new MessageScorePoints(-dieLosePoints);

}

So you can see that if "health != 0", the player spawns. But if "health == 0", I would like a Box to show up that has 3 options: "Start from Last Checkpoint", "Exit to Menu", and "Exit Game". How would I do this? I tried using OnGUI but that seems it is always on the screen and can't just call/uncall it as I wish?

Comment
Add comment · Show 1
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
avatar image BlackBoy0 · Feb 05, 2011 at 02:58 AM 0
Share

PS - Yes, I am quite new to Unity's API. Been working with the editor for awhile, but just recently got into the actual scripting of it. Only JavaScript, though.

2 Replies

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

Answer by Uriel_96 · Feb 05, 2011 at 03:00 AM

for do that kind of things you must use labels, buttons,textfield, and many others, to see more about it go to this page: http://unity3d.com/support/documentation/ScriptReference/GUI.html here you can find several ways to do what you want.

function OnGUI(){
if(health == 0){
//put your labels, buttons, textfield, etc..
}
}

this will make that it only appears when you variable health is 0 if is not 0 will disappear.

Comment
Add comment · Show 3 · 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
avatar image BlackBoy0 · Feb 05, 2011 at 03:03 AM 0
Share

Sorry, I must not have made myself that clear. I tried using "function OnGUI()", but it seems that there is no way to actually make that appear/disappear when I want? For example, only for the box/buttons to appear when "health == 0".

avatar image Uriel_96 · Feb 05, 2011 at 03:26 AM 0
Share

have you try to put something like: function OnGUI(){if(health == 0){/put your GUIs here/}}

avatar image Uriel_96 · Feb 05, 2011 at 03:27 AM 0
Share

that may work because I actually do it sometimes and it works.

avatar image
0

Answer by BlackBoy0 · Feb 05, 2011 at 08:30 AM

Oh I see what I did wrong. In the OnDeath function, when the "health == 0", I called "Destroy(gameObject);", which I guess destroys the entire gameObject, thus having no "OnGUI" to run. So I simply commented that out and the GUI started to work. Thank you Uriel :)

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

No one has followed this question yet.

Related Questions

GUI DrawTexture is sliding across the screen? 0 Answers

Health system 2d 2 Answers

[2D][Beginner]How do I heal my character when pressing a key while next to a health pack? 1 Answer

Drag and release 2 Answers

Rigidbody Collider Hero health does not drain when touched by an enemy rigidbody collider. 2 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