Disappear and then Respawn

I'm already looking for this for hours now, but I can't figure it out.

A sphere needs to disappear after 3 seconds and then reappear, but I can't get the function for this to loop in the update without starting to flash. InvokeRepeating malfunctions too with the yield waitforseconds in there.

function update() { //So that function just needs to be refreshed here or something Sphere(); }

function Sphere() { if(disappearCheck) { if(renderer.enabled == true) { yield WaitForSeconds(secondsToDisappear); renderer.enabled = false; var randomCount = Random.Range(0,5); print(randomCount); yield WaitForSeconds(randomCount); renderer.enabled = true; } } }

Ok never mind I suddenly found the answer.

Instead of waiting for 3 seconds before disappearing, I made a counter and checked if that was 3 then disappear and reset the counter to 0

I would use a variable to store the elapsed time since the last "disappear" and/or the last "respawn" of your sphere, I'm using something similar for a bridge which opens and closes at regular intervals... try something like this...

var myDelay : float = 3;
private var countTime : float = 0;

function Start() {
   countTime = Time.time;

function Update() {
   if ( (Time.time - countTime) >= myDelay) {
      // Code to make the sphere render if not render, and to hide if rendered
      countTime = Time.time;