Hi,
is it possible to somehow make a new function within the same script? It can be the same function with different parameters, so maybe there’s a way like instantiating it like a object from a class?
Background: I came up with the idea of making a simple occlusion culling for Unity free. Currently I make an empty gameobject and attach my following script for each object-(group) I want to cull:
var toCul : GameObject; //(group of) object(s) we want to be active only when we are in...
var culRange : int = 100; //...this range
function Awake() {
toCul.SetActive(false); //deactivate the "problem"-object(s) at start
}
CheckRange(0);
function CheckRange(waitFor : int) : IEnumerator {
yield WaitForSeconds(waitFor);
var curRange : int = Vector3.Distance(Camera.main.transform.position, toCul.transform.position); //range from the camera to the object
if (curRange < culRange) {
toCul.SetActive(true); //if in reach activate the object...
} else {
toCul.SetActive(false); //if not, deactivate it
}
var checkIn = Mathf.Max(0.5, 5*curRange/culRange); //the next check depends on the range from the camera to the object (for better performance)
CheckRange(checkIn);
}
It works great and currently I just have 3 of them on my empty gameobject. But I wonder how I could extend this to work on just one single script so I could store all my objects i want to cull in an array and for each index there’s automaticly made a “CheckRange”-function like in the code?
yes i have this problem when i tried to implement UNET tests.
– santiihoyos