Recursive Coroutine

i’m having problem with Recursive Coroutine.

i’m trying to show the reward that player got. Ii would be shown as sequence

however, when i started the coroutine method that show reward, it stop after showing bronze coin and do not called next method and Debug.Log()

public void appear()
	{
		Debug.Log("Coin reward 'appear' is working");
	   int[] coinFlag;	
	   currentCoin = coffin.calculateScore(); // to check that it limiitedat 2 or 3
	   if(currentCoin == 3)	
	   {
			coinFlag = new int[3]{1,0,0}; 
			StartCoroutine(show(coinFlag));
			
	   }
	   else if(currentCoin == 2)
	   {
			coinFlag = new int[3]{1,1,0}; 
			StartCoroutine(show(coinFlag));
			
	   }
	   else if(currentCoin == 1)
	   {
			coinFlag = new int[3]{1,1,1}; 
			StartCoroutine(show(coinFlag));
			
	   }
	  
	}

private IEnumerator show(int[] coinFlag) 
	{		 	
		   
		    Debug.Log("Coin reward 'show' is working");
		    if(coinFlag[0]==1)//if bronze is on
			{
				 if(coinFlag[1]==1)//if silver coin can play
			     {
				    Debug.Log("Showing bronze and show silver next");
				    int[] newCoinFlag = new int[3]{0,coinFlag[1],coinFlag[2]};
				    yield return StartCoroutine(change_Bonus_GUI_2_Size(bronzeCoin,exptWidth,exptHeight));////<<<<<<<<it stop here no calling Debug.Log('dadaddwdw');	    
				    Debug.Log("Start new coroutine with silver coin");
				    StartCoroutine(show(newCoinFlag));
				   
			     }
			     else
			     {
				    Debug.Log("Show only bronze");
				    StartCoroutine(change_Bonus_GUI_2_Size(bronzeCoin,exptWidth,exptHeight));
			     }
			}	
			else if(coinFlag[1]==1)//if silver is on
			{
				 if(coinFlag[2]==1)//if gold can play
			     {
				    int[] newCoinFlag = new int[3]{0,0,coinFlag[2]};
				    
				    silverCoin.enabled = true;
				    yield return StartCoroutine(change_Bonus_GUI_2_Size(silverCoin,exptWidth,exptHeight));
				    Debug.Log("Start new coroutine with gold coin");
				    StartCoroutine(show(newCoinFlag));
				   
			     }
			     else
			     {
				   
				    silverCoin.enabled = true;
				    Debug.Log("Show only silver");
				    StartCoroutine(change_Bonus_GUI_2_Size(silverCoin,exptWidth,exptHeight));
			     }
			}	
		    else if(coinFlag[2]==1)//if gold is on
		    {
			        
			        goldCoin.enabled = true;
			        StartCoroutine(change_Bonus_GUI_2_Size(goldCoin,exptWidth,exptHeight));
		    }
		yield return null;
	    	
	}
	
	

	
	//bonus gui pixel to specific size
	private IEnumerator change_Bonus_GUI_2_Size(GUITexture gui ,float expdX ,float expdY)
	{
		Debug.Log("change_Bonus_GUI_2_Size");
		float newW;
		float newH;
		float newX;
		float newY;
		
		while(gui.pixelInset.width != expdX  gui.pixelInset.height != expdY)
		{
			newW = Mathf.Lerp(gui.pixelInset.width,expdX,Time.deltaTime*5);
			newH = Mathf.Lerp(gui.pixelInset.height,expdY,Time.deltaTime*5);
			newX = newW*-0.5f;
			newY = newH*-0.5f;	 
			
			gui.pixelInset = new Rect(newX,newY,newW,newH);
			yield return null;
		}
	}

it may some issue of logic going on with all your if else here ^^…

well what i do in those case is repro things on small case with less code to see if intended behavior work already, so regarding your code at start where things do not work i just write a simple script simulating what you expect i guess, and this perfectly work fine

using UnityEngine;
using System.Collections;

public class ReCo : MonoBehaviour
{
	void Start()
	{
		StartCoroutine(TestCoroutine());
	}
	
	IEnumerator TestCoroutine()
	{
		var plop = 1;
		var ploplop = 1;
		
		if(plop == 1)
		{
			if(ploplop == 1)
			{
				Debug.Log("Coroutine plop now ....");
				
				yield return StartCoroutine(WaitForMe());
				
				Debug.Log("Go next step ....");
				
				StartCoroutine(ShowMeStuff());
					
			}
			else
			{
				// some stuff
			}
		}
		
		yield return null;
	}
	
	IEnumerator WaitForMe()
	{
		var counter = 200;
		
		while (counter > 0)
		{
			counter--;
			yield return null;
		}
	}
	
	IEnumerator ShowMeStuff()
	{
		Debug.Log("you see some stuff");
		yield return null;
	}
}

and debug output >>

Coroutine plop now …
Go next step …
you see some stuff

which in your example GoNext step would be your debug line and you see some stuff your Show(newCoinFlag) methods.

I suggest you break down your code inside your coroutine in smallest chucnk of code , eventually separate your sliver bronze etc within different methods to try to get more clear view for yourself

Nope it’s not working, it still stop at showing bronze coin

public void appear()
{
Debug.Log(“Coin reward ‘appear’ is working”);
int[ ] coinFlag;
currentCoin = coffin.calculateScore(); // to check that it limiitedat 2 or 3
if(currentCoin == 3)
{
coinFlag = new int[3]{1,0,0};
StartCoroutine(show(coinFlag));

}
else if(currentCoin == 2)
{
coinFlag = new int[3]{1,1,0};
StartCoroutine(show(coinFlag));

}
else if(currentCoin == 1)
{
coinFlag = new int[3]{1,1,1};
StartCoroutine(show(coinFlag));

}

}
private IEnumerator show(int[ ] coinFlag)
{

Debug.Log(“Coin reward ‘show’ is working”);

StartCoroutine(Show_bronze(coinFlag));
yield return null;
}

private IEnumerator Show_gold(int[ ] coinFlag)
{
if(coinFlag[2]==1)//if gold is on
{

goldCoin.enabled = true;
StartCoroutine(change_Bonus_GUI_2_Size(goldCoin,exptWidth,exptHeight));
}
yield return null;
yield return null;
}

private IEnumerator Show_silver(int[ ] coinFlag)
{
if(coinFlag[1]==1)//if silver is on
{
if(coinFlag[2]==1)//if gold can play
{
int[ ] newCoinFlag = new int[3]{0,0,coinFlag[2]};

silverCoin.enabled = true;
yield return StartCoroutine(change_Bonus_GUI_2_Size(silverCoin,exptWidth,exptHeight));
Debug.Log(“Start new coroutine with gold coin”);
StartCoroutine(Show_gold(newCoinFlag));

}
else
{

silverCoin.enabled = true;
Debug.Log(“Show only silver”);
StartCoroutine(change_Bonus_GUI_2_Size(silverCoin,exptWidth,exptHeight));
}
}
yield return null;
}

private IEnumerator Show_bronze(int[ ] coinFlag)
{
if(coinFlag[0]==1)//if bronze is on
{
if(coinFlag[1]==1)//if silver coin can play
{
bronzeCoin.enabled = true;
Debug.Log(“Showing bronze and show silver next”);
int[ ] newCoinFlag = new int[3]{0,coinFlag[1],coinFlag[2]};
yield return StartCoroutine(change_Bonus_GUI_2_Size(bronzeCoin,exptWidth,exptHeight));////<<<<<<<<it stop here no calling Debug.Log(‘dadaddwdw’);
Debug.Log(“Start new coroutine with silver coin”);
StartCoroutine(Show_silver(newCoinFlag));

}
else
{
bronzeCoin.enabled = true;
Debug.Log(“Show only bronze”);
StartCoroutine(change_Bonus_GUI_2_Size(bronzeCoin,exptWidth,exptHeight));
}
}
yield return null;
}

I’m using itween to help this intead and it works .but anyway, thanks giyomu for reply in this thread.

public void appear()
{
Debug.Log(“Coin reward ‘appear’ is working”);
int[ ] coinFlag;
currentCoin = coffin.calculateScore(); // to check that it limiitedat 2 or 3
if(currentCoin == 3)
{
coinFlag = new int[3]{1,0,0};
show(coinFlag);

}
else if(currentCoin == 2)
{
coinFlag = new int[3]{1,1,0};
show(coinFlag);

}
else if(currentCoin == 1)
{
coinFlag = new int[3]{1,1,1};
show(coinFlag);

}

}

private void show(int[ ] coinFlag)
{

Debug.Log(“Coin reward ‘show’ is working”);
if(coinFlag[0]==1)//if bronze is on
{
if(coinFlag[1]==1)//if silver coin can play
{
bronzeCoin.enabled = true;
Debug.Log(“Showing bronze and show silver next”);
int[ ] newCoinFlag = new int[3]{0,coinFlag[1],coinFlag[2]};
iTween.ValueTo(gameObject,iTween.Hash(“time”,0.5,
“from”,0,
“to”,exptHeight,
“onUpdate”,“change_bronze_GUI_2_size”,
“onComplete”,“show”,
“onCompleteTarget”,gameObject,
“onCompleteParams”,newCoinFlag
));

}
else
{
bronzeCoin.enabled = true;
Debug.Log(“Show only bronze”);
iTween.ValueTo(gameObject,iTween.Hash(“time”,0.5,
“from”,0,
“to”,exptHeight,
“onUpdate”,“change_bronze_GUI_2_size”
));
}
}
else if(coinFlag[1]==1)//if silver is on
{
if(coinFlag[2]==1)//if gold can play
{
int[ ] newCoinFlag = new int[3]{0,0,coinFlag[2]};

silverCoin.enabled = true;
iTween.ValueTo(gameObject,iTween.Hash(“time”,0.5,
“from”,0,
“to”,exptHeight,
“onUpdate”,“change_silver_GUI_2_size”,
“onComplete”,“show”,
“onCompleteTarget”,gameObject,
“onCompleteParams”,newCoinFlag
));

}
else
{

silverCoin.enabled = true;
Debug.Log(“Show only silver”);
iTween.ValueTo(gameObject,iTween.Hash(“time”,0.5,
“from”,0,
“to”,exptHeight,
“onUpdate”,“change_silver_GUI_2_size”
));
}
}
else if(coinFlag[2]==1)//if gold is on
{

goldCoin.enabled = true;
iTween.ValueTo(gameObject,iTween.Hash(“time”,0.5,
“from”,0,
“to”,exptHeight,
“onUpdate”,“change_gold_GUI_2_size”
));
}

}

private void change_gold_GUI_2_size(float size)
{
float newW = size;
float newH = size;
float newX = newW*-0.5f;
float newY = newH*-0.5f;
goldCoin.pixelInset = new Rect(newX,newY,newW,newH);
}

private void change_silver_GUI_2_size(float size)
{
float newW = size;
float newH = size;
float newX = newW*-0.5f;
float newY = newH*-0.5f;
silverCoin.pixelInset = new Rect(newX,newY,newW,newH);
}

private void change_bronze_GUI_2_size(float size)
{
float newW = size;
float newH = size;
float newX = newW*-0.5f;
float newY = newH*-0.5f;
bronzeCoin.pixelInset = new Rect(newX,newY,newW,newH);
}