My goal is a randomly rotating asteroid. The solution is quiet ok, but I am wondering a little.
According to the reference, the min and max-values are inclusive. Therefore I would anticipate values between 0 and 2 for the temp variable. But it is just 0 and 1. And furthermore just the _rotation[cnt] with the index equal to temp gets an other value then zero…checked now some thing, typecasting the Random.Range(1,9) / 10; to float solves this problem. But this means the reference is wrong, because it says:
Or do I misunderstand something?
public class AsteroidRotation : MonoBehaviour {
public float[] _rotation= new float[3];
private int temp;
// Use this for initialization
void Start () {
temp = (int)Random.Range(0,2);
Debug.Log(temp);
for (int cnt = 0; cnt <3; cnt++){
if (cnt == temp){
_rotation[cnt] = Random.Range(1,20);
Debug.Log("Cnt: " + cnt + " Random: " + _rotation[cnt] );
}
else {
_rotation[cnt] = Random.Range(1,9) / 10;
Debug.Log("Cnt: " + cnt + " Random: " + _rotation[cnt] );
}
}
}
// Update is called once per frame
void Update () {
transform.Rotate(_rotation[0]* Time.deltaTime,_rotation[1]* Time.deltaTime ,_rotation[2]* Time.deltaTime);
}
}