- Home /
How can I make a color wave effect?
Basically I have a game where the player moves along tiles and must tap when the player is within a target on the tile. When this happens, I want to have a "flash" of white starting from the centre of the tile spreading outwards in all 4 directions until it hits the edge of the cube, where the flash then dissapears. I would like this flash the take the shape of a hollow square, where it's alpha fades out on the inside edges.
I am still learning Unity so please don't assume I know even basic things.
Answer by highpockets · Jun 02, 2019 at 08:44 PM
You can fake this by making a transparent texture in the shape you want and then put it on a quad with a transparent material. Scale it down to nothing and have it slightly higher than the tile at which it makes the effect above. When you want to trigger the effect, scale up gradual via the Vector3.Lerp() function until it reaches your target size.
Vector3.Lerp(startScale, endScale, scalingTimer);
Try that, if you have troubles, post your code.
Cheers,
Thank you. How exactly would I go about making a texture? lol...
In photoshop, $$anonymous$$rita, gimp, etc.. Then you can import it as a sprite into unity
Ohh I see ok. Thanks alot it really helped.
Hey, I have an issue. I gave me an error saying a non-convex mesh collider is not compatible with rigidbody, even though I dont have a rigidbody. I removed the mesh collider from the quad, and the error went away, but the ripple effect isnt showing. Im not asking you to hold my hand, but Im really confused.
private IEnumerator Ripple()
{
Vector3 startScale = new Vector3(0 , 0 , 0);
Vector3 endScale = new Vector3(2 , 2 , 2);
float t = 0.5f;
while (ripple.transform.localScale.x < 2)
{
ripple.transform.localScale = Vector3.Lerp(startScale , endScale , t);
yield return new WaitForEndOfFrame();
}
Destroy(ripple);
}
You are not updating the ‘t’ variable that represents the timer for the lerp function and you start it at 0.5f which will make the scale (1,1,1) always because it never changes. You want to start that timer at 0.0f and change it each frame. Also, that is the only thing I see wrong in the coroutine, but I don’t know where you are calling the coroutine from. You need to make sure you are not calling multiple coroutines. Post your whole script if you like
private IEnumerator Ripple()
{
Vector3 startScale = new Vector3(0 , 0 , 0);
Vector3 endScale = new Vector3(2 , 2 , 2);
float t = 0.0f;
while (ripple.transform.localScale.x < 2)
{
ripple.transform.localScale = Vector3.Lerp(startScale , endScale , t);
yield return new WaitForEndOfFrame();
t += Time.deltaTime;
}
Destroy(ripple);
}
That will make the scale change from (0,0,0) to (2,2,2) in 1 second