This piece of Javascript is giving me troubles.
var originalPosition : Vector3;
var osHeight = 0.05;
var delay = 0;
function Start () {
// when the object starts, we record its initial position
originalPosition = transform.position;
}
function Update () {
// Set the x position to loop between values osHeight and a set delay.
transform.position.y = originalPosition.y + Mathf.Sin(Time.time + delay) * osHeight;
Debug.Log("YPosition = " + transform.position.y);
}
All seems fine but only runs on play when the object is selected like this:
![alt text][1]
Otherwise it doesn't run.
I've tried the debugger and I've noticed that the y position does oscilate. However the value on the object and of YPosition is different.
![alt text][2]
Why is this happening and how do I fix this?
Sorry if it's a really simple question. I've tried googling answers but can't seem to fix it.
[1]: /storage/temp/85145-15878440-10154000913202035-59620455-o.png
[2]: /storage/temp/85147-untitled-2.png
↧