How to work with statics?

Hey there!

This must be a really noob question. Anyway, I want to store the initial position of an object

This is what I have before the function update:

static var iniposx :float;
static var iniposy :float;
static var iniposz :float;

iniposx = transform.position.X;
iniposy = transform.position.Y;
iniposz = transform.position.Z;
static function initialpos(iniposx, iniposy, iniposz) : Vector3

I can see with the console that initialpos.magnitude is always changing.

var v3_starting_position : Vector3;

function Start() {
    v3_starting_position = gameObject.transform.position;
}

That ought to work. function Start() only runs right when the scene is loaded (shortly after function Awake() ) so that’s the perfect time to store the starting location. Reference v3_starting_position later as needed.

Thanks! That did the trick :slight_smile:

One could think that just because it’s outside the update function, it’s not being executed all the time.

Exactly!