- Home /
Hitpoints Tagged
I was wondering if you could tag this script instead of having on collision.
var damage : float;
function OnCollisionEnter (other : Collision){ // Tell the object you hit that it was damaged other.collider.gameObject.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver); }
i want it so i can add a tag to the object so that it will apply damage to that object. EX... i want it to have a collision with object that is tagged apply damage = 100
Answer by aldonaletto · Dec 05, 2011 at 02:43 AM
If you want to check the hit object's tag, do the following:
var damage : float;
function OnCollisionEnter (other : Collision){ if (other.transform.tag == "someTag"){ // Tell the object you hit that it was damaged other.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver); } } NOTE: Remember to place an ApplyDamage(damage: float) function in the object you want to damage.
Thanks for your script edited it and got it working so that i could just place a tag and it would take hit points away without having to attach another script.
Your answer
![](https://koobas.hobune.stream/wayback/20220613061802im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
casting a raycast from the raycast hit.point 1 Answer
Looking for a Better Way to check Multiple Tags 2 Answers
How can I get the tag of a child object? 1 Answer
Count >= then object tag becomes active 1 Answer
OnTriggerEnterProblem 1 Answer