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;
}
}