Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Nov 03, 2015 at 02:06 PM by fafase for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DoctorSqueaks · Nov 03, 2015 at 08:49 AM · c#programming

Math Doesnt Make Sense

The enemy spawns in with 100hp, the gun does 5hp of damage per shot. But whenever I shoot the enemy, it's health goes to a ridiculous number eg. -5568, and back to 100 instantly.

 private float health = 1000;
 private float weaponDamage = 5;
 
     public void EnemyDamage() {
         health -= weaponDamage;
         print (health);
         if (health <= 0) {
             Die();
         }
     }
 
     void Die() {
         Destroy (gameObject);
     }

alt text

screenshot-4.png (18.9 kB)
Comment
Add comment · Show 6
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 Fire_Cube · Nov 03, 2015 at 09:35 AM 1
Share

I can't see the error there, haven't you another script that modify the health property? also, is the gameobject destroy imediately? Also, with the console, i see that between two prints, the health value get down of 13, so i think the script is modified somewhere else...

avatar image DoctorSqueaks Fire_Cube · Nov 03, 2015 at 10:37 AM 0
Share

Alright, I'll go through the rest of my code and look for anything. Thanks :)

avatar image meat5000 ♦ DoctorSqueaks · Nov 03, 2015 at 10:48 AM 0
Share

The script you post and the output you display dont match up. You got 2 scripts on the go?

I see Enemy hit which suggests you have an OnCollisionEnter somewhere interfering with it (as thats the kind of debug output people put there). Is that script also dealing damage?

Show more comments
avatar image Bonfire-Boy · Nov 03, 2015 at 12:55 PM 1
Share

I would recommend turning off the Collapse option in the console, it only gets in the way of understanding what's going on in these kind of situations. Personally, the only time I would have it turned on is when I'm specifically interested in the number of times a line is being hit.

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by DoctorSqueaks · Nov 03, 2015 at 12:50 PM

I've worked out what's happening, every time I spawn the prefab, the health doesn't reset back to 100, which is why, after a couple hours of work, I was getting ridiculous numbers.

Comment
Add comment · 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

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Which of the Two is Better?? 2 Answers

Faster alternative to GetComponentInParent() method? 1 Answer

How can I adjust a different touch spots on the object 0 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