I want to turn the mesh renderer off on runtime but for some reason the mesh renderer gets disabled but the object still can be seen; I tried turning the component itself off and also tried turning the renderer of (renderer.enable = false;)
Here is the script Im using, it disables the renderer depending of how far the Player is, I have a similar script for turning lights off that works perfectly
using UnityEngine;
using System.Collections;
public class Betolder : MonoBehaviour {
public float availableDistance;
private float Distance;
///------------------------------
// Update is called once per frame
void Update () {
GameObject Player = GameObject.FindGameObjectWithTag("Player");
MeshRenderer MeshComponent = gameObject.GetComponent<MeshRenderer>();
Distance = Vector3.Distance(Player.transform.position, transform.position);
if (Distance < availableDistance){
renderer.enabled = true;
}
if (Distance > availableDistance){
renderer.enabled = false;
}
}
}
This one works too, the Mesh renderer gets disabled but the object still there like nothing happened, is weird because If I turn the Mesh renderer off in the editor the object its not rendered at all so I dont understand why I cant do the same thing on runtime.
[17123-weid+thing.jpg|17123]