- Home /
Variables from one script to another.
My code doesn't show any errors, but doesn't take health away. The point is that if my fireBall collides with an enemy the enemy loses as much health as there is damage. here's the script :
void OnTriggerStay(Collider other)
{
if (other.GetComponent<removeHealth>())
other.GetComponent<removeHealth>().health -= damage;
}
and yes I have an object that has a script removeHealth active. removeHealth also has a public health float in it.
Answer by Phan-Phantz · Apr 16, 2016 at 08:44 AM
Try to store damage variable in fireBall and health variable in enemy when it collides with the enemy try this health -= other.damage;
Answer by KaushikRahul · Apr 16, 2016 at 07:14 AM
Please check if you have non-Kinematic Rigidbody attached to one of the colliding objects. I guess you are missing Rigidbody.
Answer by Max1mus · Apr 17, 2016 at 12:07 PM
@Dhicci If you're using "Trigger", make sure "Is Trigger" is checked on the "other", but I would suggest using OnCollisionEnter(Collision col). Also before actually taking the health away, to make sure that collision actually occurs, try Debug.Log("Collided");
Eeem... you are right. I was missing is Trigger, but when I check "is Trigger" the object falls through terrain. I will try OnCollisionEnter(Collision col)