- Home /
Why isn't OnTriggerEnter/Exit working?
Im trying to make a simple way of turning mesh renderers of blocks on and off based on whether the blocks enter the trigger or exit. When they enter, i want their renderer to be active, and when they exit i want their renderer to be disabled. This script feels like it should be working fine, but neither of them display the Debug.Log. The script is attatched to the trigger, and the blocks of rigidbodies. Im working with about 2000 instantiated blocks that unity batches.
using UnityEngine;
using System.Collections;
public class renderBlock : MonoBehaviour {
public Transform player;
void Update() {
transform.position = player.transform.position;
}
void OnTriggerEnter(Collider other) {
if(other.gameObject.tag == "block") {
Debug.Log("block entering field");
other.gameObject.renderer.enabled = true;
}
}
void OnTriggerExit(Collider other) {
if(other.gameObject.tag == "block") {
Debug.Log("block exiting field");
other.gameObject.renderer.enabled = false;
}
}
}
Answer by AyJayKaySoft · Aug 25, 2012 at 06:08 PM
just use print()? print even only works in the editor...
that doesn't help with the main issue at hand. The printing/debugLog is only for me to check if they function registered the gameobject.
Answer by Piflik · Aug 25, 2012 at 07:01 PM
Make sure you have triggers on every object and rigidbodies on at least one member of any trigger even (preferably the moving one).
what do you mean? in my case the moving trigger is the box attatched to the player. Why would i put triggers on each object?
Because that's how triggers work. A trigger only reacts to objects that have triggers themselves.