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 /
This question was closed Dec 05, 2013 at 01:46 AM by clunk47 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Doneyes · Aug 15, 2013 at 12:24 AM · errordebugdamagehealth

"Health" value doesn't change?

This is a piece of my script. The health value equals what I tell it to, but each time it calculates it as if the Health value doesn't change at all. Anything look weird in this:

 if(other.collider.GetComponent(HealthSystem)) {
         HealthS = other.collider.GetComponent(HealthSystem);
         Health = HealthS.Central.GetComponent(CentralHealth).Health;
         if(HealthS.IsHead == true) {
             Debug.Log("Hit something!");
             Health = Health - Damage;
         }
         if(HealthS.IsTorso == true) {
             Debug.Log("Hit something!");
             Health = Health - Damage / 2;
         }
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

  • Sort: 
avatar image
1
Best Answer

Answer by clunk47 · Aug 15, 2013 at 12:43 AM

Instead of Health = Health - Damage, try using

 Health -= Damage;

With little to go off of though, not knowing what your other scripts hold, an easy way to do this would be:

 other.collider.gameObject.GetComponent(HealthSystem).Health -= Damage;
Comment
Add comment · Show 4 · 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 Doneyes · Aug 15, 2013 at 12:57 AM 0
Share

Still not working. It's taking away damage, but it's like I'm saying health = 100 - damage every time. It's changing the health back to 100 every time.

If I manually change it, the value stays what I change it to. If I shoot it, it calculates the value but never actually gives it the value. It's weird. (I have a debug that states the value)

avatar image clunk47 · Aug 15, 2013 at 12:58 AM 1
Share

Post the full script. health = 100 - damage is obviously always going to be 100 $$anonymous$$us damage the way you have it lol. Like what I said, use health -= damage!

avatar image Linus · Aug 15, 2013 at 12:59 AM 0
Share

I think there error is in another place then. Perhaps in HealthSystem or CentralHealth

avatar image Doneyes · Aug 15, 2013 at 01:11 AM 0
Share
 var particle : GameObject;
 var life : int = 15;
 var HealthS;
 var Health;
 var Damage : int = 50; //This is the max damage.
 
 function Start () {
     life = life * 100;
 }
 
 function Update () {
 life -= Time.deltaTime * 100;
     if(life == 0) {
         Destroy (gameObject);
     }
 }    
      
 function OnCollisionEnter(other : Collision) {
     if(other.collider.GetComponent(HealthSystem)) {
         Debug.Log("This1");
         HealthS = other.collider.GetComponent(HealthSystem);
         Debug.Log("This2");
         Health = HealthS.Central.GetComponent(CentralHealth).Health;
         Debug.Log("This3");
         Debug.Log(Health);
         if(HealthS.IsHead == true) {
             Debug.Log("Hit something!");
             Health -= Damage;
         }
         if(HealthS.IsTorso == true) {
             Debug.Log("Hit something!");
             Health -= Damage / 2;
         }
         if(HealthS.IsArm == true) {
             Health -= Damage / 3;
         }
         if(HealthS.IsLeg == true) {
             Health -= Damage / 2.5;
         }
         if(HealthS.IsOther == true) {
             Health -= Damage / 2;
         }
         Debug.Log(Health);
     }
     else {
         Debug.Log(other.collider.name + " Does not have HealthSystem script attached! ");
     }
     
     //if(hit.gameObject.tag != "$$anonymous$$etal" && hit.gameObject.tag != "Wood" && hit.gameObject.tag != "Stone" && hit.gameObject.tag != "Dirt") {
     
     //}
     
     Destroy (gameObject);
     }

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Expecting ) found = 1 Answer

Unity Error: Only assignment, call, increment, decrement, and new object expressions can be used as a statement 1 Answer

How to make keystore debugging ? 0 Answers

Damage to Health 2 Answers

Enemy health drops but not if first enemy lives, how do i change that? 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