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 BigBlob · Mar 13, 2012 at 02:52 AM · playerreloaddiehealth

Dying Problem!

I have a perfect script that works perfectly fine but when the health of the player reaches 0 it loads the level again but then the scene its loaded as if the player is already dead so the level is loaded and loaded again and again.

Script :

     var h00 : Texture2D;
 var h10 : Texture2D;
 var h20 : Texture2D;
 var h30 : Texture2D;
 var h40 : Texture2D;
 var h50 : Texture2D;
 var h60 : Texture2D;
 var h70 : Texture2D;
 var h80 : Texture2D;
 var h90 : Texture2D;
 var h100 : Texture2D;
 
 static var HEALTH = 100;
 
 function Update()
 {
     var g_Health = gameObject.Find("g_Health");
     
     if(HEALTH > 100)
     {
         g_Health.guiTexture.texture = h100;
         return;
     }
     else if (HEALTH > 90)
     
     {
         g_Health.guiTexture.texture = h90;
         return;
     }
     else if (HEALTH > 80)
     
     {
         g_Health.guiTexture.texture = h80;
         return;
     }
     else if (HEALTH > 60)
     
     {
         g_Health.guiTexture.texture = h60;
         return;
     }
     else if (HEALTH > 50)
     {
         g_Health.guiTexture.texture = h50;
         return;        
     }
     else if (HEALTH > 40)
     {
         g_Health.guiTexture.texture = h40;
         return;        
     }
     else if (HEALTH > 30)
     {
         g_Health.guiTexture.texture = h30;
         return;        
     }
     else if (HEALTH > 20)
     {
         g_Health.guiTexture.texture = h20;
         return;        
     }
     else if (HEALTH > 10)
     {
         g_Health.guiTexture.texture = h10;
         return;        
 
     }
     else if (HEALTH <= 0)
     {
         g_Health.guiTexture.texture = h00;
         Application.LoadLevel(1);
     }
 }

  • Felipe

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
1

Answer by rutter · Mar 13, 2012 at 03:38 AM

This line gets my attention:

    static var HEALTH = 100;

A static variable is shared throughout an entire program. Any time you change the value of HEALTH, you're changing the value for every instance of that script, even if it's attached to multiple characters, even if those characters are in different levels. Are you sure that's what you want?

I see two obvious solutions:

  • If you're not sure what a static variable is, you can probably just get rid of the static keyword.

  • If you're using a static variable intentionally, you'll probably want to reset HEALTH before loading a new level.

Comment
Add comment · Show 2 · 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 BigBlob · Mar 13, 2012 at 04:53 PM 0
Share

I cant do one of these two because if I set static my otter scripts will need the HEALTH to be a static, what about Public will that be a good?

avatar image DavidDebnar · Mar 13, 2012 at 05:10 PM 0
Share

public and static are two different options. Why do you need the HEALTH to be static? I don't suppose that you share the same HEALTH with all the players and if you do, than make one empty gameObject and make all the players update the HEALTH trough that.

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

6 People are following this question.

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

Related Questions

Restart with GUIText 2 Answers

Photon Network Health Script 0 Answers

Player taking damage on collision. Can't get the script to work!? 1 Answer

Respawn Player after Health 0 1 Answer

How do i stop player to move when dead 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