• 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
Question by tayyab43 · Jan 21, 2014 at 10:38 PM · c#bulletdamagediehealth

bullet damage problem

I wrote a collision and bullet damage script, bullet is tagged as bullet and both are rigid bodies plus both triggers are checked so i can't figure out why it isn't working?

using UnityEngine; using System.Collections;

public class BulletDamage : MonoBehaviour {

 public int HEALTH=100;    
 public GameObject bullet;    
 static public int bulletDamage = 25;
 public GameObject clavicle;
 public GameObject soldier;
 void OnTriggerEnter(Collider other)
     {
     if(other.tag == "bullet");
         {
         HEALTH = HEALTH - bulletDamage;
         }

 
     if (HEALTH<=0)
     {
         clavicle.transform.parent = soldier.transform; 
         animation.Play("soldierDieFront");
     }    
 }
                                         }
Comment

People who like this

0 Show 3
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 getyour411 · Jan 21, 2014 at 11:23 PM 1
Share

Add to your OnTriggerEnter line of

 Debug.Log(other.name + " " + other.collider);

basically prove that what you are expecting to hit the trigger is

avatar image tayyab43 · Jan 22, 2014 at 07:28 AM 0
Share

the OnTriggerEnter line? how exactly ould i do it

avatar image moghes · Jan 22, 2014 at 09:15 AM 0
Share

Do you mean that Health is not being decremented by 25? As getyour411 suggested, Debug to see if you are entering the if statement.

 if(other.tag == "bullet");
 {
        Debug.Log("HEALTH before decrement:  " + HEALTH );
 
        HEALTH = HEALTH - bulletDamage;
 
        Debug.Log("new HEALTH value:  " + HEALTH );    
 
 }

for example, smth like this, you can see the old and new value of health, if you dont see any printed line in the console, then the problem is with the tag, maybe you have not assigned.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by HappyMoo · Jan 22, 2014 at 05:22 PM

if Both are rigid Bodies and moved by physics, they don't trigger each other, but collide.

See t$$anonymous$$s to understand: http://www.youtube.com/watch?v=WFkbqdo2OI4

Also, for fast moving bullets, what you're trying to do isn't ideal either, because the bullet could miss the body or you need to step up the simulation precision. I'd recommend to use raycasts to find out where you $$anonymous$$t

Comment

People who like this

0 Show 0 · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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 avatar image avatar image avatar image

Related Questions

Health and Damage [C#] 2 Answers

hi I know that this script is seen often but I have an another problem with a damage and health scripts. I think it's the GetComponent part, well anyway if you could help that would be great. 2 Answers

how to take health/hearth from player when colliding with an object? 2 Answers

Player Health Damage 2 Answers

My Photon health script doesnt work 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