How to trigger a bool with a collision?

I am trying to make a script (in C#) which detects if an object is colliding with a box collider. It will then set a bool value to true or false, which is used in another script.

I dont get any errors when it runs, but nothing happens. Here is my current collision detection script:

public class BackDetect : MonoBehaviour {

	public bool backCol;

	public void OnTriggerEnter (Collider other)
	{

		if (other.gameObject.tag == "World") {
			backCol = true;
		} else if (other.gameObject.tag != "World") {
			backCol = false;
		}

	}
}

Can someone please tell me if this is wrong or if theres another way to do it.

First, put a Debug.Log("backCol value: " + backcol); on the last line of you OnTriggerEnter(). so that you know wether or not this function is even called and the value it sets.

in case its not being called,

  • are you sure the object this script is attached to has its collider set to Trigger ?

  • does one of the 2 objects have a rigidbody attached?, else you wont get any collision/trigger functions being called

Ok I solved the problem.

I OnTriggerStay instead of OnTriggerEnter, It seems to work for my situation.