void Start()
{
objects = 0;
}
// Update is called once per frame
void Update()
{
Debug.Log(objects);
}
void OnTriggerEnter(Collider col)
{
objects ++;
Debug.Log(col.name);
}
void OnTriggerExit(Collider col)
{
objects --;
Debug.Log(col.name);
}
If I add this script to a prefab that I have got and I move it into other objects it should show me how many objects it is colliding with. It does that but for some reason it says there is always 0 too. For instance I make sure the object collides with 3 other objects, it will debug saying 3, but at the same time it also debugs 0. its like every frame it says 0 and 3.
So for instance when I add a simple boolean saying: if(Objects == 5){ thisBoolean = true }, it will never actually set it to true, even if I make it collide with 5 objects, it will set it to true and then false again in the same frame.
I have no clue how to get this to work properly. I am pretty certain I had the code working on an earlier Unity version, but now at 5.1 it doesn’t seem to work.
Please help me get rid of my headache