Camera Color Changing Script Help

Hi,

I wanted to put a changing color background in my game, and have done it with the main camera.

I edited the basic Unity Script Reference script to add more colors, and it came up with this error:

Assets/Standard Assets/Scripts/Camera Scripts/Camera Colour Strobe.js(15,45): BCE0017: The best overload for the method ‘UnityEngine.Color.Lerp(UnityEngine.Color, UnityEngine.Color, float)’ is not compatible with the argument list ‘(UnityEngine.Color, UnityEngine.Color, UnityEngine.Color, UnityEngine.Color, float)’.

Here is my edited script:

#pragma strict

// ping-pong animate background color
var color1 : Color = Color.red;
var color2 : Color = Color.blue;
var color3 : Color = Color.yellow;
var color4 : Color = Color.green;
var duration = 3.0;

// Set clear flags to color
camera.clearFlags = CameraClearFlags.SolidColor;

function Update () {
var t : float = Mathf.PingPong (Time.time, duration) / duration;
camera.backgroundColor = Color.Lerp (color1, color2, color3, color4, t);
}

Can someone help me? :face_with_spiral_eyes:

Thanks,

TheThingThatDies

PS. If you see the same thing on the Answers site. I went to the wrong place. :slight_smile:

why not code sky box to change colors in a loop

Lerp only accepts 3 parameters; the first value, the second value, then your third parameter is used to lerp between those two values.

If you only write -

camera.backgroundColor = Color.Lerp (color1, color2, t);

it will work, although that will only go between two colour values. You’d probably need a bit more code if you want to cycle between more colours.

Why thank you for that information :smile: