//==Audio==// public void PlayCoinAudio(CoinControler coin) { audioSource.Stop(); switch (coin.coinTypes) { case CoinControler.CoinTypes.Penny: audioSource.clip = pennyAudio; break; case CoinControler.CoinTypes.Nickel: audioSource.clip = nickelAudio; break; case CoinControler.CoinTypes.Dime: audioSource.clip = dimeAudio; break; case CoinControler.CoinTypes.Quarter: audioSource.clip = quarterAudio; break; case CoinControler.CoinTypes.Half: audioSource.clip = halfAudio; break; default: audioSource.clip = pennyAudio; break; } audioSource.Play(); }
void OnTriggerExit2D(Collider2D col) { CoinControler coin = col.gameObject.GetComponent <CoinControler>(); if (col.tag == "Coin" && !completed) { sprite.color = Color.white; correctSprite.alpha = 0f; if (gm.difficulty == GameManager.Difficulty.Beginner) { coinSprite.alpha = 1f; } } }
void OnTriggerEnter2D(Collider2D col) { CoinControler coin = col.gameObject.GetComponent <CoinControler>(); if (col.tag == "Coin" && !completed) { if (gm.difficulty == GameManager.Difficulty.Beginner) { if (coin.coinTypes.ToString() == coinTypes.ToString()) { sprite.color = Color.green; correctSprite.spriteName = "Correct"; correctSprite.alpha = 1f; gm.PlayMatchAudio(true); gm.activeCoins--; gm.correctNum++; SetComplete(); coin.matched = true; } else { coinSprite.alpha = 0f; sprite.color = Color.red; correctSprite.spriteName = "Incorrect"; correctSprite.alpha = 1f; gm.PlayMatchAudio(false); gm.incorrectNum++; } } else if (gm.difficulty == GameManager.Difficulty.Advanced) { if (targetValue + coin.value <= 100) { sprite.color = Color.green; correctSprite.spriteName = "Correct"; correctSprite.alpha = 1f; gm.PlayMatchAudio(true); targetValue += coin.value; if (targetValue == 100) { gm.correctNum++; SetComplete(); } coin.matched = true; } else { sprite.color = Color.red; correctSprite.spriteName = "Incorrect"; correctSprite.alpha = 1f; gm.PlayMatchAudio(false); gm.incorrectNum++; } } else if (gm.difficulty == GameManager.Difficulty.Expert) { if (currentValue + coin.value <= targetValue) { sprite.color = Color.green; correctSprite.spriteName = "Correct"; correctSprite.alpha = 1f; gm.PlayMatchAudio(true); currentValue += coin.value; if (currentValue == targetValue) { gm.correctNum++; SetComplete(); } coin.matched = true; } else { sprite.color = Color.red; correctSprite.spriteName = "Incorrect"; correctSprite.alpha = 1f; gm.PlayMatchAudio(false); gm.incorrectNum++; } } UpdateLabel(); } }