Having a OnTriggerEnter make another gameobject Add Force in UnityScript.

Using javascript, I was experimenting with OnTrigger functions with a trigger game object, I thought about triggering another gameobject to add force. Problem is, I don’t understand how it would work with a OnTriggerEnter function after adding a “if” statement for identifying a tag or gameobject to detect.

How does one achieve this when using two separate OnTriggers like Enter and Exit.

Does that mean I have to use a function update if I don’t create another separate script for the game object that has add force?

Thanks.

So I dont really know Javascript… so imma just answer in C#… sorry. But it is pretty similar so… you will be fine :slight_smile:

If I understood you correctly you want to add force to an object when it enters a trigger. Here is what you wanna do:

void OnTriggerEnter(Collider coll){
if(coll.tag == "YourTag")
coll.getComponent<Rigidbody>().addForce(yourVector);
}

Sorry its not formatted… wrote it on the fly :slight_smile:

So… does this help? :smiley: