I’m making a racing simulator and I made this script for a replay system. But when i tried it it didn’t add any elements, they just stayed at 3. this is how it looked :
#pragma strict
var recorded_obj : GameObject;//Object to record
var Positions : Vector3[];
var Rotations : Quaternion[];
var replayPosition : int;
function Start ()
{
}
function Update ()
{
AddPos();
AddRot();
if(Input.GetKey("r"))
{
Replay();
}
else
{
replayPosition = 0;
}
}
function AddPos()
{
var positionsarr = new Array(recorded_obj.transform.position);
positionsarr.length += 1;
positionsarr.Add(recorded_obj.transform.position);
Positions = positionsarr;
}
function AddRot()
{
var rotationsarr = new Array(recorded_obj.transform.rotation);
rotationsarr.length += 1;
rotationsarr.Add(recorded_obj.transform.position);
Rotations = rotationsarr;
}
function Replay()
{
//Position
recorded_obj.transform.position = Positions[replayPosition];
//Rotation
recorded_obj.transform.rotation = Rotations[replayPosition];
replayPosition += 1;
}
What’s wrong? I’ve read the Add() description in the scripting API, and it says that it adds a for example value to the end of the Array.