Script for changing object color after a certain time?

I need help on how to change the color of an object, It will be red when the player can’t shoot. Then green when the player is able to shoot/launch a bullet by pressing the space bar.

Red= reloading/cant shoot
Green= able to shoot

And if possible, can you possibly make a script to where the object slowly fades in when reloading. Then when its green the object is fully there, when red the object isn’t there and slowly starts to fade into the scene.

(if you need me to further explain I will do so! Because I thought that was pretty confusing :smile:)

Thank you,
Wade

protected IEnumerator FlashTo (Color fromColor, Color toColor, float time) {

	float lerp=0.0f;
	
	while (lerp < 1) {
		
		lerp += Time.deltaTime/time;
		
		foreach (SkinnedMeshRenderer render in renderers) {
			
			render.material.color = Color.Lerp (fromColor, toColor, lerp);
			
		}
		
		yield return null;
		
	}
	
}

Should get you started.

Thank you very much :slight_smile: I’m so glad people help out with scripting :stuck_out_tongue: I just don’t understand it…

Do you maybe have the other one? Where it slowly fades in, then the object gets launched out of the basket when green, then another (clone) will start to slowly fade in while its reloading?

The code posted above handles the fading.

Most of the time, its purely aesthetic. With this in mind, what you want to be doing is:

  1. Call the coroutine with x time passed in
  2. Wait x time
  3. Fire

To change the color instantly, you can alter renderer.material.color

Note that you probably won’t be able to copy+paste my code as it uses an array of SkinnedMeshRenderers.

What does it mean to “use an array of SkinnedMeshRenderers.”

So what would I have to do to fix it so I wont have any problems?

And how do I change the color?

var time : 10
{
If.time = 0, then color.Red
else = Green
}

Haha, I highly doubt that is even close to being right, if it is then I would feel like I just won 1,000,000 :smile: