- Home /
Question by
smirlianos · Apr 22, 2013 at 04:46 PM ·
javascriptinstantiatematerialcolorrandom.range
Random.Range doesn't work
Hello!
I make a game where you control a spaceship and as you move, planets are appearing. But when they Instantiate, they look like they have self-illumin material. This happens because the script that I use exept of keeping the r & g variables between 0-255 as to make a color combination, it makes them to >2000.
#pragma strict
var Earth : GameObject;
function Update () {
var n : int = Random.Range(0,1000);
var r : int = Random.Range(0,255);
var g : int = Random.Range(0,255);
if(n == 1)
{
var planet = Instantiate(Earth, transform.position, transform.rotation);
planet.renderer.material.color = Color(r, g, 0, 0);
}
}
Comment
Best Answer
Answer by AlucardJay · Apr 22, 2013 at 04:49 PM
The Color parameters are between 0 and 1 , not 0 and 255 =]
Each color component is a floating point value with a range from 0 to 1. : http://docs.unity3d.com/Documentation/ScriptReference/Color.html
Oh, you're right! Confused from photoshop and stuff! Thank you!