I'm trying to make a set of tiles on the floor of my 3d world visible only when the Player is nearby them. This will work as single tile prefabs. Just not if I set them within an empty parent gameobject... which is what I really need, ideally, for the sake of game performance.
Once I put them inside the empty parent gameobject, OnTrigger stops working or even registering (debug.log doesn't show anything).
Does anyone know the correct way to access and switch the MeshRenderer on/off via OnTrigger (or OnCollision might be even better... I've tried and same issue) when I have a LevelManager that loads all my game objects at runtime? The Level Manager instantiates a prefab (clone), which has an empty gameobject that's holding the tiles as children?
Code I've tried and that's not working so far:
public class CubeVis : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other)
{
Debug.Log("hit");
if (other.gameObject.CompareTag("Cube"))
{
Debug.Log("hittt");
//other.gameObject.GetComponentInParent<MeshRenderer>().enabled = true;
// other.gameObject.GetComponentInChildren<MeshRenderer>().enabled = true;
//other.gameObject.GetComponent<MeshRenderer>().enabled = true;
}
}
Inspector/Hierarchy info as requested:












