- Home /
How to change color as flashing or blink?
Hi Guys
İ have a problem. I want you change color my object. But i'm doing this process send scoop.
only once draw into scoop and change once.
help me!
Color clr = hit.collider.gameObject.renderer.material.color;
oilTikİc = !oilTikİc;
if( oilTikİc )
{
clr.r = Mathf.MoveTowards(0.1f, 0.5f, Time.deltaTime);//new Color( 1.0f, 1.0f,1.0f);
clr.g = Mathf.MoveTowards(0.1f, 0.5f, Time.deltaTime);
clr.b = Mathf.MoveTowards(0.1f, 0.5f, Time.deltaTime);
hit.collider.gameObject.renderer.material.color = clr;
}
else
{
clr.r = Mathf.MoveTowards(0.5f, 0.0f, Time.deltaTime);
clr.g = Mathf.MoveTowards(0.5f, 0.0f, Time.deltaTime);
clr.b = Mathf.MoveTowards(0.5f, 0.0f, Time.deltaTime);
hit.collider.gameObject.renderer.material.color = clr;
}
Sorry, but t is hard for me to understand your question, could you please clear it up?
There are two issues here. For a $$anonymous$$oveTowards to work, it needs to be called repeatedly...usually in Update(). If your code is being called each frame, then you are flipping the 'oldTikIc' boolean variable each frame. The second problem is that you are not using $$anonymous$$oveTowards() correctly. That is, the first parameter needs to be the current color. It cannot be a fixed value.
I don't understand the desired behavior well enough to show you an exact fix for your code. Your title using 'flashing or blink', but the use of $$anonymous$$oveTowards seems to indicate that you want to fade from one color to another. Note you may want to explore the Color.Lerp() function. And also if all you want is a flashing light, search Unity Answers for 'flashing light'.