Based on the new info you gave, using OnCollisionExit is the wrong way to go about what you are doing here. OnCollisionExit should be used when two non-trigger colliders exit a collision (eg. the moment they bounce off each other).
Even if OnCollisionExit was the right choice, you would be using it wrongly in your code. On line 8, the “Collider secretion” bit doesn’t check if secretion is the collider. OnCollisionExit passes on information about the collision and you should use it with a Collision class like this “OnCollisionExit(Collision myCollision)”.
OnTriggerExit uses the Collider class eg. “OnTriggerExit(Collider other)”, where “other” will simply tell you the collider of the other gameObject.
So let’s make this all work!
You’ll need to set the collider of “secretion” as “Is Trigger”. This will work whether you’re using a boxcollider like you are now or a mesh collider like you plan in the future.
using UnityEngine;
using System.Collections;
public class GravitySecretion : MonoBehaviour
{
public Collider secretion; // Set the secretion collider in inspector
void OnTriggerExit(Collider other) //When this gameobject's collider exits another (trigger) collider, "other" is the other collider
{
if (other == secretion) //if the other collider is the same one as "secretion"
{
GetComponent<Rigidbody>().AddForce(Vector3.up * -10, ForceMode.Acceleration);
}
}
}
Hi !
I made the mesh I want to replace the cube with, for the secretion zone.
It gets tricky because it has more than 256 faces or what and it can’t be a collider because of that…
So I’m asking myself should I find another way than OnTriggerExit that doesn’t require a collider?
Or is there a way to go around that faces limitation? … That sucks, I wonder how they do in pro games for like complex rivers or what… Maybe I should just get down the faces count…