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 dreamevolved · Nov 28, 2012 at 02:48 PM · healthbarlifelifebarhealth

Spinning Pointer that reacts when health drops

Hey all! So I have already had quite a bit of help with the need equation to get the spinner to move. But then I realized I had no idea how to combine the two pieces of information I have.

So I have this: alt text

The Needle is its own object so that it may spin freely. Here is the sample of code I was given to power the spinner.

 needle.transform.rotation = Quaternion.Euler( 0, needleDegreeOffset + health/maxHealth * needleDegreeRange, 0 );

And here is the script I am using to manage my character controller's health.

 // These variables are used for the player's health
 var curHP:float=100;
 var maxHP:float=100;
 
 
 
 // This is the player's money
 var Money:int=0;
 
 
 function ChangeHP(Change:float)
 {
     // This line will take whatever value is passed to this function and add it to curHP.
     curHP+=Change;
     
     // This if statement ensures that we don't go over the max health
     if(curHP>maxHP)
     {
         curHP=100;
     }
     
     // This if statement is to check if the player has died
     if(curHP<=0)
     {
         // Die
         Debug.Log("Player has died!");
     }
 }
 
 // This function checks if the player has entered a trigger
 function OnTriggerEnter(other:Collider)
 {
     // The switch statement checks what tag the other gameobject is, and reacts accordingly.
     switch(other.gameObject.tag)
     {
     case "Heal":
         ChangeHP(25);
         break;
     case "Hurt":
         ChangeHP(-25);
         break;
     case "Money":
         Money+=25;
         break;
     }
     // Finally, this line destroys the gameObject the player collided with.
     Destroy(other.gameObject);
 }

Now the part where I am lost is how to make these two pieces work when they are independent objects, one being the needle, and the other being the character controller that is in fact receiving the damage. Would the needle script be an entirely different script that references the health script? And if so, how would I connect them? Sorry for all the questions, still really new at scripting.

Thanks for the time and consideration!

healthguage.png (30.3 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

Regain health on GUI 2 Answers

How to make a camera's background be another camera's veiw 1 Answer

Player health dropping far to fast 1 Answer

rect.width gets set to 0 for unknown reason 1 Answer

Help me with scripting please 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