- Home /
collision on child only returns parent object ?
Hi, I'm trying to Damage only the child of an object on Projectile impact, but instead it just damages the parent object. :
I have a Damage function in the "Enemy" script wich is attached to both the parent and the child, and i'm accessing it from my Bullet script attached to the bullet blueprint :
public void Damage(int bla)
{
Health -= bla;
if (Destructable) {
if (Health <= 0) {
Destroy (gameObject);
}
}
}
Bullet script:
void OnCollisionEnter (Collision other){
print (other.gameObject.name); // this returs that the name is the name of the parent object
if (other.gameObject.tag == "Enemy" ) {
other.gameObject.GetComponent<EnemyScript> ().Damage (projectileDamage);
}
}
How would i set it up if i only want to deal Damage to the child if the child is hit ?
Comment
Best Answer
Answer by Tom507 · Dec 23, 2017 at 10:16 PM
nevermind I found the Answer i just had to get the gameobject of the collider, it works like this now
void OnCollisionEnter (Collision other){
print (other.gameObject.name);
if (other.gameObject.tag == "Enemy" ) {
other.collider.gameObject.GetComponent<EnemyScript> ().Damage (projectileDamage);
}
}