Greetings,
This is fixed, see for the code at the bottom.
I had an issue. It had to do with the following code:
var camver : int;
/// To recall at what camera position it is right now, and to which one it has to go.
var timesensitivity : float;
/// How fast the timer goes.
var timetaker : float;
var campositions : Vector3[] = new Vector3[4];
var camrotation : Vector3[] = new Vector3[4];
function Start () {
camver = 0;
timesensitivity = 1;
timetaker = 4;
campositions[0] = Vector3(38,5,67);
campositions[1] = Vector3(43,3,78);
campositions[2] = Vector3(56,2,64);
campositions[3] = Vector3(44,1,64);
camrotation[0] = Vector3(24, 50, 350);
camrotation[1] = Vector3(4,50,-1);
camrotation[2] = Vector3(4,160,4);
camrotation[3] = Vector3(-8, 100, -3);
}
function Update () {
if(timetaker > 0) {
timetaker -= timesensitivity * Time.deltaTime;
} else {
camver += 1;
timetaker = 15;
transform.position = campositions[camver];
transform.Rotate(camrotation[camver]);
}
if (camver >= 3){
camver = 0;
}
}
Now, these are the errors:
IndexOutOfRangeException: Array index is out of range. > Fixed
CameraRotation.Start () (at Assets/Menu/Scripts/CameraRotation.js:17) > Fixed
&
IndexOutOfRangeException: Array index is out of range. > Not Fixed
CameraRotation.Update () (at Assets/Menu/Scripts/CameraRotation.js:38) > Not Fixed
What the code is supposed to do, is use the arrays to quickly switch positions & rotations every 15 seconds, the timetaker, to the desired position & rotation, using camver to get to the right part of the array.
I’ve tried some things, and they all gave me an error, this is the code I have now.
Now, the question is, is what did I do wrong with declaring the array (or something else?), and how can I fix this?
And, is there a way to make the code more efficient, because I think arrays are (in this situation) the most efficient approach.
Any help would be greatly appreciated!
Jip
Edit: updated with the new script, same issue.
Edit: The proper script that works:
(PS: Note that the values of the arrays are given inside the inspector)
var camver : int;
/// To recall at what camera position it is right now, and to which one it has to go.
var timesensitivity : float;
/// How fast the timer goes.
var timetaker : float;
var timetakervalue : float;
var campositions : Vector3[];
var camrotation : Vector3[];
function Start () {
timetaker = timetakervalue;
}
function Update () {
if(timetaker > 0) {
timetaker -= timesensitivity * Time.deltaTime;
} else {
camver += 1;
timetaker = 15;
transform.position = campositions[camver];
transform.Rotate(camrotation[camver]);
}
if (camver >= 3){
camver = -1;
}
}