- Home /
Help with simple scripting?
Hello! I want my gameobject (cube) to change it's color in a loop. I would also like to have my loop stop after about 30 seconds. I tried to make a script for it but it didn't work. If my script is'nt even close to what I'm trying to do, could someone make me one or tell me what's wrong in it.
yield WaitForSeconds (16.8);
{
for {
renderer.material.color = Color(1, 0, 0, 1);
yield WaitForSeconds (0.183);
{
renderer.material.color = Color(0, 1, 0, 1);
yield WaitForSeconds (0.183);
{
renderer.material.color = Color(1, 0.92, 0.016, 1);
yield WaitForSeconds (0.183);
{
renderer.material.color = Color(0, 0, 1, 1);
yield WaitForSeconds (0.183);
}
}
}
}
}
Answer by mattssonon · Nov 15, 2013 at 08:37 AM
Your code syntax looks very odd. I would structure your code like this:
function FunctionName() {
yield WaitForSeconds (16.8);
renderer.material.color = Color(1, 0, 0, 1);
yield WaitForSeconds (0.183);
renderer.material.color = Color(0, 1, 0, 1);
yield WaitForSeconds (0.183);
renderer.material.color = Color(1, 0.92, 0.016, 1);
yield WaitForSeconds (0.183);
renderer.material.color = Color(0, 0, 1, 1);
yield WaitForSeconds (0.183);
}
However, the first WaitForSeconds (16.8)
waits for 16.8 seconds before changing color the first time, so that's probably not what you're after. After that you then change colors with 0.183 seconds between each switch, which is extremely fast, try increasing those values.
Your answer
Follow this Question
Related Questions
{Solved}Trying to add color loop to background using Vector4 2 Answers
Color index operator not working properly 1 Answer
Negative Color Scheme 2 Answers