Trouble move a object up and down with a script

Hi.

I try to move a object up, wait for some seconds and the move it down again, and then start the movement over and over again. Like a continuous lift so to say but without any Player to trigger it.

In the Unity documents I found a script doing something close to this, but I don’t get it right when I tries to make it loop forever. When I compile it Unity complain about a cycle… but that is what I want isn’t it?

var startMarker: Transform; // start her
var endMarker: Transform;   // stopp her
var speed = 1.0;
var smooth = 5.0;

private var startTime: float;
private var movementDistance: float; // distance between the markers

	
	function Start() {

		startTime = Time.time; // Keep a note of the time the movement started.

	}
	
	
	function Update () {
		
		GoingUp () ;
	}
	
	
	function GoingUp () {
	
		movementDistance = Vector3.Distance(startMarker.position, endMarker.position);
	
		var distCovered = (Time.time * speed);

		var fracJourney = distCovered / movementDistance;
		
		transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
		
		yield WaitForSeconds (5);
		
		GoingDown () ;
	}
		
	function GoingDown () {
		
	
		movementDistance = Vector3.Distance(endMarker.position, startMarker.position);
	
		var distCovered = (Time.time * speed);

		var fracJourney = distCovered / movementDistance;
		
		transform.position = Vector3.Lerp(endMarker.position, startMarker.position, fracJourney);
		
		yield WaitForSeconds (5);
		
		// GoingUp () ;
	}

update is called every frame, so you can’t call GoingUp in there. You’ll have to review your logic. I’m not sure what it does, you may be able to call it in the start function if the function actualy does all the motion without needing to be called every frame. Otherwise, you will need to rewrite the update so it controls both the up and down being called every frame. You may need a bool called up, if it’s true, call going up each frame, if it’s false, call going down each frame, and set the bool in the function rather than calling the other one.

Hi thanks

I modified the code so everything inside GoingUp is inside a IF statement and it need a bool to be true, it seems to work better but when I do the same with GoingDown (and bool to be false), Unity still complain about a cycle… Don’t know how to fix that…