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 Noah-1 · Jan 13, 2011 at 07:54 PM · texturesprogress-bardecreasehealth

Problem with HealthBar

Well im new here guys.

I want to tell you that I am making a game for the iphone and well I have some problems but the most important now is the health bar, here is the code:

// Player goes here:

var Warrior: GameObject;

//Here are the textures of the health

var Health1: Texture2D; var Health2: Texture2D; var Health3: Texture2D;

//Times Dead

var fall = 0;

//Some Code

function Update () {

// If the player falls, the healthbar will decrease

if(Warrior.transform.position.y < -2 )

{

gameObject.Find ("Health");

//Change the HealthBar

guiTexture.texture = Health2;

fall = 1; //Now the fall times increases to 1, untill here all is ok

} }

if(Warrior.transform.position.y < -2 && fall == 1){

gameObject.Find ("Health");

//Change the HealthBar

guiTexture.texture = Health3;

}

Does anybody see a problem there?

My code does not has errors but the bar only decreases to Health2 if I fall again it doesnt decrease to Health3.

Some help?

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

Answer by Ejlersen · Jan 13, 2011 at 09:00 PM

That code is a bit weird.

  1. Why the Finds? You're not using the "Health" thingy-ma-jig anyways.
  2. The last if-statement is outside the Update function.
  3. Putting the last if-statement inside the Update function will give you a health bar with Health3 when y < -2, because you will set fall = 1 and y < -2 will still be correct.
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 Noah-1 · Jan 13, 2011 at 09:38 PM 0
Share

O$$anonymous$$, i putted the second if on the update function, it worked but on the first fall it decreases to the health 3 automatically. I want the bar to decrease in different falls but I dont know how to specify the second, third etc.. falls

avatar image Ejlersen · Jan 14, 2011 at 03:52 PM 0
Share

Think about your own code like this: If y < -2, then set to Health2 and set fall to 1, later you check again if y < -2 and if fall is 1, then set to Health3. Both situations are true in the same cycle. This is bad, since you won't see Health2. Therefore you need to check when its below -2 and when its above. If it goes from greater than -2 to less then -2, then you have to change to Health2. Then reset the check when you are above -2 again. You can use a boolean for this.

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

progress bar 1 Answer

How to move 2D textures? 0 Answers

Changing Mesh of an object depending on Health Value. C# 2 Answers

I made my code so that if i hit an enemy its health will go down but when i hit the enemy the health doesnt go down. please help 1 Answer

How do i add a healthbar/actionbar gui 4 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