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
2
Question by cidmodder · Nov 15, 2010 at 07:11 PM · guideathhitpoints

An on death pop up GUI

I am using this script on a character to have an enemy apply damage to the character.

var maximumhitPoints = 100;

var hitPoints= 100;

function ApplyDamage (damage:float) { if (hitPoints < 0) return;

//apply damage

hitPoints --;

if (hitPoints <= 0)

Die(); }

function Die() { if (hitPoints <=0)

//insert GUI here

}

but I'm having trouble understanding how to do GUI. All I want is for a window to pop up when you die that says you died and you can click an ok button. is this:

static function Window (id : int, clientRect : Rect, func : WindowFunction, content : GUIContent) : Rect

what I need to use? Thanks!

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

2 Replies

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

Answer by Yoerick · Nov 15, 2010 at 07:50 PM

If you want to write a GUI in code it should be done in the function OnGUI(), you can't write GUI code inside one of your own functions. In your case you could use a boolean to check if a player is dead or not, like so:

var isDead = false;

function OnGUI() { if (isDead) { GUI.Box(Rect(left, top, width, height), "You're dead"); if(GUI.Button(Rect(left, top, width, height), "Click here")) { isDead = false; } } }

function die() { if(hitpoints <= 0) isDead=true; }

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 cidmodder · Nov 15, 2010 at 08:51 PM 0
Share

what exactly are the values? are they just the size of the box?

avatar image cidmodder · Nov 15, 2010 at 09:13 PM 0
Share

and the error compiler keeps telling me i need a ; after the boolean

avatar image Yoerick · Nov 16, 2010 at 07:39 AM 0
Share

I changed the values so it's clear what they stand for ;) Sorry for the bool error, I usually code in c# and "bool" is a c# sharp type, in JavaScript it's just "var".

avatar image
0

Answer by bhuszi · Nov 16, 2010 at 08:21 AM

function OnGUI() { print(""+boxselecting);

if(boxselecting){

 var width : int = leftupbox.x - rightdownbox.x;

 var height : int = (Screen.height - leftupbox.y) - (Screen.height - rightdownbox.y);

 var rect : Rect = Rect(rightdownbox.x, Screen.height - rightdownbox.y, width, 

height);

//GUI.Box(rect, "Its ALIVE");

 GUI.Box(Rect(rightdownbox.x, Screen.height - rightdownbox.y, width, height), "Its ALIVE");

 //GUI.DrawTexture(rect, selectionTexture, ScaleMode.StretchToFill, true, 10.0f);

 print("GUI");

}

} this is my code for drwng a box and unity still gives me the GUI can only be called in OnGUI error whats wrong with my code?

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 not counting Player Deaths 3 Answers

Javascript GUI and deathscript weird compiler errors 1 Answer

Help with calling and naming functions! 2 Answers

How will i get animated gif images in scene? 6 Answers

GUI.TextField problem, won't update var. 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