c# wait script

Hi,

I am looking to make an object lerp left and right across the screen. i have the object lerping from one point to another but i need it to repeat from moving from right to left and back to right and so on. What is the best way to do this and how can you make it wait 1sec before it moves. if you need anymore info let me know. thanks for the help.

void Update () {
StartCoroutine(wait());
}
public IEnumerator move () {
yield return new WaitForSeconds (1.0f); //this stops the coroutine for 1 second.
Vector3 positionA = new Vector3 (3, 2, 0);
Vector3 positionB = new Vector3 (2, 2, 0);

         transform.position = Vector3.Lerp(transform.position, newPosition, smooth * Time.deltaTime);

} 

I hope this helped.

timers have been covered so many times. a simple search should yield good results.

but heres a little script just for you :smiley:

using UnityEngine;
using System.Collections;

public class moveWait : MonoBehaviour {

	float moveDelay = 1f;
	float smooth = 0.1f;
	float currentDelay;
	
	bool canMove = true;
	bool moveToA = true;
	
	Vector3 positionA = new Vector3(3,2,0);
	Vector3 positionB = new Vector3(2,2,0);
	
	void Start()
	{
		currentDelay = Time.time + moveDelay;


	}
	
	
	void Update()
	{
		if(canMove)
		{
		if(transform.position != positionA && moveToA)
		{
		moveToPosition(positionA); //start moving;
		}

		if(transform.position == positionA && moveToA)
		{
			moveToA = false;
			canMove = false;
			currentDelay = Time.time + moveDelay;
		}

		if(transform.position != positionB && !moveToA)
		{
			moveToPosition(positionB); //start moving;
		}
		
		if(transform.position == positionB && !moveToA)
		{
			moveToA = true;
			canMove = false;
			currentDelay = Time.time + moveDelay;
		}
		}

		if(!canMove && Time.time > currentDelay)
		{
			canMove = true;
			currentDelay = Time.time + moveDelay;
		}
		

			
	}


	void moveToPosition(Vector3 target)
	{
		transform.position = Vector3.Lerp(transform.position, target,  Time.deltaTime);
	}

}