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 dannondarko · Jan 03, 2014 at 03:47 AM · health

Why won't my death function work?

var curHealth : int = 100; var maxHealth : int = 100; var healthtext : GUIText;

function Start () {

} function Update () { healthtext.text = "Health: " + curHealth + " / " + maxHealth; if(curHealth < 0 ) { curHealth = 0; } if(curHealth > 100) { curHealth = 100; } if(curHealth <= 0) { Dead(); } function Dead() { transform.position = Vector3 (1, 2.5, 1); curHealth = maxHealth; } }

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 ncallaway · Jan 03, 2014 at 04:15 AM

I'm guessing you're seeing syntax errors based on the code-snippet you posted. When you say your death function doesn't work are you seeing the following syntax errors?

 BCE0044: expecting (, found 'Dead'.
 UCE0001: ';' expected. Insert a semicolon at the end.

If so, then the problem is the (accidental?) nesting of the Dead function within the Update function. I've reformatted the original snippet that you've posted (with the Start function removed). Note how the Dead() function is actually nested within the Update() function:

 var curHealth : int = 100;
 var maxHealth : int = 100;
 var healthtext : GUIText;
 
 function Update () {
     healthtext.text = "Health: " + curHealth + " / " + maxHealth;
     
     if(curHealth < 0 ) {
         curHealth = 0;
     }
     
     if(curHealth > 100) {
         curHealth = 100;
     }
     
     if(curHealth <= 0) {
         Dead();
     }
     
     function Dead() {
         transform.position = Vector3 (1, 2.5, 1);
         curHealth = maxHealth;
     }
 }

The syntax errors will disappear if you change the order of your curly braces, so that Dead() is no longer nested within the Update() function, it looks something like this:

 var curHealth : int = 100;
 var maxHealth : int = 100;
 var healthtext : GUIText;
 
 function Update () {
     healthtext.text = "Health: " + curHealth + " / " + maxHealth;
     
     if(curHealth < 0 ) {
         curHealth = 0;
     }
     
     if(curHealth > 100) {
         curHealth = 100;
     }
     
     if(curHealth <= 0) {
         Dead();
     }
 }
 
 function Dead() {
     transform.position = Vector3 (1, 2.5, 1);
     curHealth = maxHealth;
 }

If the syntax errors weren't your problem, would you clarify what you meant by "my death function won't work"

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 dannondarko · Jan 03, 2014 at 07:15 AM 0
Share

Thank you, I found that out now. Thank you very much for your feed back. How do you post code like that on here?

avatar image tanoshimi dannondarko · Jan 03, 2014 at 07:23 AM 0
Share

Look on the right hand side of the page for the link that says "To help users post good questions and use the site effectively we have posted a tutorial video. Please check it out."

It will also show you how to post comments as comments, not as answers, and how to mark answers as correct... I've done it for you this time ;)

avatar image dannondarko · Jan 03, 2014 at 07:18 PM 0
Share

You're good, man. Too Good.

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

20 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 avatar image avatar image avatar image avatar image

Related Questions

health problem 1 Answer

Health does not update in this script, why? 1 Answer

Can someone write me a health script? 2 1 Answer

I need Help with the bergzerg arcade Melee combat scripts 1 Answer

Damage script is screwed up...? what to do? 1 Answer


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