Start a coroutine,when its finished start second coroutine ,when second coroutine finished repeat from the first coroutine ??

that coroutines make me sleepless ,need help :smiley:
i have a list of points i want first coroutine to move a gameobject for every point in the list when finished
start other coroutine but backward of the list until i=0 ,and repeat ect. here is some script

`
void Start(){

StartCoroutine(forward());
}

IEnumerator forward(){

		print("first"); 

		for( int i=0;i<points.Count;i++)
		{
			transform.localPosition=points*;*
  •   		yield return new WaitForSeconds(1);*
    
  •   }*
    
  • StartCoroutine(backward());*

  • }*

  • IEnumerator backward(){*

  •   	print("in 2");* 
    
  •   	for( int i=points.Count;i>=0;i--)*
    
  •   	{*
    

_ transform.localPosition=points*;*_

* yield return new WaitForSeconds(0.1f);*
* }*
* print(“leave 2”);*
* StartCoroutine(forward());*
* }*
`
so the second repeat doesn’t start one after one but they run at the same time
thank you .

Why don’t you merge the two functions?

void Start()
{
	StartCoroutine(PingPong());
}

IEnumerator PingPong()
{
	int i ;
	WaitForSeconds longWait = new WaitForSeconds(1);
	WaitForSeconds shortWait = new WaitForSeconds(0.1f);
	while( true )
	{
		for( i = 0 ; i < points.Count ; i++ )
		{
			transform.localPosition = points*;*
  •  	yield return longWait;*
    
  •  }*
    
  •  for( i = points2.Count - 1; i>=0 ; i-- )*
    
  •  {*
    

_ transform.localPosition=points2*;_
_
yield return shortWait;_
_
}_
_
}_
_
}*_