Hi, I have a problem with a platform moving from A to B. When I restart the level the platform will be at the exact same position it was even before I restarted. I have both tried to specify start position of the Platform, and now I’m even loading another level before loading back to the level with the platform, but still the same problem. I am not using static variables, and the script is rather simple:
//Moves an object from StartX/StartY to the X and Y of the posEndDistance,
//taking the time specified in the duration variable, moving back and
//forward.
//Problem: The object seems to remember where it was after reloading the
//level, even if I load another level first.
var StartX : float;
var StartY : float;
var duration : float = 1.0;
var posEndDistance : Vector3;
private var posStart : Vector3;
private var posEnd : Vector3;
function Awake ()
{
posStart = Vector3(StartX, StartY, 0);
posEnd.x = transform.position.x + posEndDistance.x;
posEnd.y = transform.position.y + posEndDistance.y;
posEnd.z = 0.0; //Overriding since this is for 2D game
}
function Update ()
{
var lerp = Mathf.PingPong (Time.time, duration) / duration;
transform.position = Vector3.Lerp (posStart, posEnd, lerp);
}
http://pastebin.com/y12nZBQE
Your Using Mathf.PingPong with Time.time, so it’s getting the time from your apps start. I’d recommend Incrementing a float variable by Time.deltaTime in update and using that as your time.
Thank you very much Precursor. I now got it to reset like it should since I now use deltaTime instead (which resets properly). However (and I am on thin ice here), shouldn’t I be multiplying with deltaTime instead of adding? If I multiply nothing happens 
//Moves an object from StartX/StartY to the X and Y of the posEndDistance,
//taking the time specified in the duration variable.
var StartX : float;
var StartY : float;
var duration : float = 1.0;
var posEndDistance : Vector3;
private var Speed : float = 1000;
private var posStart : Vector3;
private var posEnd : Vector3;
function Awake ()
{
posStart = Vector3(StartX, StartY, 0);
posEnd.x = transform.position.x + posEndDistance.x;
posEnd.y = transform.position.y + posEndDistance.y;
posEnd.z = 0.0; //Overriding since this is for 2D game
}
function Update ()
{
Speed = Speed + Time.deltaTime;
var lerp = Mathf.PingPong (Speed, duration) / duration;
transform.position = Vector3.Lerp (posStart, posEnd, lerp);
}
Mathf.PingPong takes the first argument and constrains it between 0 and the second argument, meaning Speed can be anything from 0 to semi-infinity. Since duration is 1.0, you just need to add Time.deltaTime to speed. If duration wasn’t 1.0, you would have to multiply it by Time.deltaTime before adding it to speed. Hope that cleared this up.