The only problem is, that I am running in a performance issue, if there are many objects, that blink. Is there a way to abandon the sine? I think, that would help already.
Of course, there is a much better solution. You can enable/disable it’s renderer.
renderer.enabled = false;
If you want to make it blink, you can do the following:
var blink : boolean = true;
function blink()
{
var myRend:MeshRenderer = GetComponent(MeshRenderer); //Apply the MeshRenderer component to the myRend variable
var myState:boolean = true; //Makes our state true
while(blink) //While our state is true
{
myState = !myState; //Change our state to the oposite
myRend.enabled = myState; //Id our state is enabled, the renderer will be enabled. If our state is disabled, the rendeder will be disabled
yield WaitForSeconds(0.25); //Waits for 0.25 seconds
}
}
dunno if it is faster, but simply using the time in an algorithm would probably suffice. It would be something like this. (it solves for the in and out time, makes sure its a factor of 2, subtracts 1 then Abs’s the result, thus giving you a number that goes from 0 to 1 to 0)
var cycleTime=2.0;
private var originalColor : Color;
function Start(){
originalColor=renderer.material.color;
cycleTime=Mathf.Abs(cycleTime);
if(cycleTime==0.0)cycleTime=1.0;
}
function LateUpdate(){
var timer=Time.time / cycleTime;
timer=Mathf.Abs((timer - Mathf.Floor(timer)) * cycleTime - 1);
renderer.material.color = Color.Lerp( originalColor, Color.white, timer );
}
It is not clear to me, what you do with cycleTime in the Start-Methode, but your LateUpdate-Function is working fine, even with a constant value as cycleTime. Thank you very much.