- Home /
Question by
Unity3DJava · Jul 28, 2013 at 01:58 AM ·
renderrenderwithshader
Looping Renderer
I want to figure out how to loop this code when ever i start the scene it does what I want ,but then just flickers. I want it to do what it executed the first time instead of flickering.Heres my code:
var wait : float;
var rend : float;
function Rendering () {
renderer.enabled = false;
yield WaitForSeconds(rend);
renderer.enabled = true;
}
function Update () {
Rendering();
Destroy();
}
function Destroy() {
yield WaitForSeconds(wait);
Destroy(gameObject);
}
Comment
Best Answer
Answer by robertbu · Jul 28, 2013 at 03:01 AM
I'm guessing a bit on how you want this to behave, but here is an alternate solution:
var wait : float;
var rend : float;
function Start() {
InvokeRepeating("Rendering", 0.0, rend);
Destroy(gameObject, wait);
}
function Rendering () {
renderer.enabled = !renderer.enabled;
}
Note that Destory() takes an alternate parameter for how long in the future to execute the destroy. Also the way you had this code structured, you were stacking up a large number of coroutines (i.e. you were getting two new coroutines every time Update() is called.