What i am trying to do is set whether or not an object should be simulateded. If a player is within 100 units it should render and simulate the rigidbody, if not then it should disable the game object. However when i try to reactivate it will not work.
@HideInInspector
var PO : GameObject;
@HideInInspector
var D: Vector3;
@HideInInspector
var rendered : boolean = true;
@HideInInspector
var CT : float;
var RenderDistance : float = 100;
var CheckTime : float = 2;
function Awake()
{
PO = GameObject.FindGameObjectWithTag("Player");
}
function Update ()
{
CT += Time.deltaTime;
if(CT >= CheckTime)
{
D = GameObject.FindGameObjectWithTag("DistanceProbe").GetComponent("PlayerDistanceMonitor").PlayerPosition;
if(Vector3.Distance(transform.position, D) > RenderDistance)
{
gameObject.active = false;
}
if(Vector3.Distance(transform.position, D) < RenderDistance)
{
Debug.LogError("This is still working");
gameObject.active = true; //however this isnt
}
}
}
I have tried this also by just disabling the physics constraints and renderer. But when it reactivates the mesh renderer does not activate also… Any ideas?