IEnumerator DisplayText(int value, float time) { CustomText text = Instantiate(texts[6]).GetComponent <CustomText>(); text.Display(value); text.gameObject.transform.position = new Vector3(0, -0.25f); float current = 0; float alpha = 1; while (current < time) { text.gameObject.transform.localScale = new Vector3(0.1f, 0.1f) + alpha * new Vector3(0.1f, 0.1f); text.gameObject.GetComponent <Renderer>().material.color = new Color(1, 1, 1, alpha); alpha = 1f - current / time; current += 0.05f; yield return(new WaitForSeconds(0.025f)); } Destroy(text.gameObject); }
void Start() { //PlayerPrefs.SetInt("Profit", 0); //PlayerPrefs.SetInt("AllScore",0); //PlayerPrefs.SetInt("GameCounter", 0); //PlayerPrefs.SetInt("BestScore", Random.Range(500,1000)); audio = gameObject.AddComponent <AudioSource>(); profit = PlayerPrefs.GetInt("Profit"); bestScore = PlayerPrefs.GetInt("BestScore"); allScore = PlayerPrefs.GetInt("AllScore"); gameCounter = PlayerPrefs.GetInt("GameCounter"); if (allScore < 1000) { allScore = 1000; } if (gameCounter < 10) { gameCounter = 10; } if (JavaInterface.Java()) { if (bestScore < 500) { bestScore = Random.Range(500, 1000); } playerText = Instantiate(texts[5]).GetComponent <CustomText>(); playerText.transform.parent = transform; playerText.transform.position = new Vector3(-1.125f, 0.5f); playerText.transform.localScale = new Vector3(0.15f, 0.15f); scoreText = Instantiate(texts[7]).GetComponent <CustomText>(); scoreText.transform.parent = transform; scoreText.transform.position = new Vector3(-1.125f, 0.40f); scoreText.transform.localScale = new Vector3(0.075f, 0.075f); //scoreText.Init(); //scoreText.Display(0); //playerText.gameObject.SetActive(false); } else { mAuidoOption = Instantiate(audioOption).GetComponent <OptionAnimation>(); mAuidoOption.transform.parent = transform; mAuidoOption.transform.localScale = new Vector3(1.5f, 1.5f, 1f); mAuidoOption.transform.position = new Vector3(1.15f, 0.575f); //Debug.Log(mAuidoOption); EventListener.Get(mAuidoOption.gameObject).onClick += (GameObject obj) => { mAuidoOption.OnClick(); }; EventListener.Get(mAuidoOption.gameObject).onPress += (GameObject obj) => { mAuidoOption.OnPress(); }; EventListener.Get(mAuidoOption.gameObject).onFree += (GameObject obj) => { mAuidoOption.OnFree(); }; } mChopLeft = Instantiate(chopLeft).GetComponent <ChopAnimation>(); mChopRight = Instantiate(chopRight).GetComponent <ChopAnimation>(); mChopLeft.transform.parent = transform; mChopRight.transform.parent = transform; mChopLeft.transform.position = new Vector3(-0.75f, -0.125f); mChopRight.transform.position = new Vector3(0.75f, -0.125f); mChopLeft.Hide(); mChopRight.Hide(); gameText = Instantiate(texts[4]).GetComponent <CustomText>(); gameText.transform.parent = transform; gameText.transform.position = new Vector3(0, 0.25f); gameText.transform.localScale = new Vector3(0.25f, 0.25f, 1); gameText.gameObject.SetActive(false); mMainPanel = Instantiate(mainPanel).GetComponent <PanelAnimation>(); lastScoreText = Instantiate(texts[6]).GetComponent <CustomText>(); lastScoreText.transform.parent = mMainPanel.transform; lastScoreText.transform.localScale = new Vector3(0.1f, 0.2f); lastScoreText.transform.position = mMainPanel.transform.position + new Vector3(0, -0.675f); bestText = Instantiate(texts[6]).GetComponent <CustomText>(); bestText.transform.parent = mMainPanel.transform; bestText.transform.position = mMainPanel.transform.position + new Vector3(0, -0.425f); bestText.Display(bestScore); mScroll = Instantiate(scroll).GetComponent <ScrollAnimation>(); mScroll.transform.position = new Vector3(0, 0.65f); mScroll.transform.parent = transform; mScroll.gameObject.SetActive(false); mScrollMain = Instantiate(scrollMain).GetComponent <ScrollAnimation>(); mScrollMain.transform.position = new Vector3(1.2f, -0.15f); mScrollMain.transform.parent = transform; mScrollMain.GetComponent <Renderer>().material.color = new Color(1, 1, 1, 0); for (int i = 0; i < mScrollMain.transform.childCount; i++) { mScrollMain.transform.GetChild(i).GetComponent <Renderer>().material.color = new Color(1, 1, 1, 0); } mAwards = mScrollMain.GetComponent <AwardsAnimation>(); mScrollMain.gameObject.SetActive(false); if (JavaInterface.Java() == true) { mWelcome = Instantiate(welcomeArcade).GetComponent <WelcomeAnimation>(); } else { mWelcome = Instantiate(welcomeMobile).GetComponent <WelcomeAnimation>(); } mWelcome.transform.position = transform.position; mWelcome.transform.parent = transform; //mWelcome.transform.localScale = new Vector3(2, 2); mWelcome.Hide(); mWelcome.gameObject.GetComponent <Collider>().enabled = false; GameEvent.onGetScore += OnGetScore; GameEvent.onDeath += OnDeath; GameEvent.onFinishGame += OnFinishGame; GameEvent.onReset += OnReset; GameEvent.startReset += StartReset; GameEvent.finishReset += FinishReset; GameEvent.onHealth += OnHealth; GameEvent.onStartGame += OnStartGame; GameEvent.onWelcome += OnWelcome; GameEvent.offWelcome += OffWelcome; GameEvent.waitStartGame += WaitStartGame; GameEvent.onLaunchGame += OnLaunchGame; EventListener.Get(mWelcome.gameObject).onClick += (GameObject obj) => { GameController.isLaunchGame = true; }; EventListener.Get(mChopLeft.gameObject).onPress += (GameObject obj) => { GameController.isLaunchGame = true; GameEvent.OnAttackLeft(PlayerController.players[0]); }; EventListener.Get(mChopRight.gameObject).onPress += (GameObject obj) => { GameController.isLaunchGame = true; GameEvent.OnAttackRight(PlayerController.players[0]); }; InputPort.onChangeScoreEvent += (int value) => { playerText.Display(value / 10, 0.1f); scoreText.Display(value % 10, 0.1f); }; }
void SetGameScore(int value) { gameScore = value; gameText.Display(gameScore); }
void OnDeath(PlayerInfo player) { if (player.index == 0) { int award = 0; audio.clip = dieMarch; audio.Play(); mScroll.gameObject.SetActive(false); mScrollMain.gameObject.SetActive(false); gameText.gameObject.SetActive(false); allScore = allScore + gameScore; gameCounter = gameCounter + 1; switch (awards) { case 0: break; case 1: award = 1; //Debug.Log("铜奖"); break; case 2: award = 2; //Debug.Log("银奖"); break; case 3: award = 3; allScore = (int)(0.8f * allScore + gameScore); gameCounter = (int)(0.8f * gameCounter + 1); //Debug.Log("金奖"); break; case 4: award = 5; allScore = (int)(0.5f * allScore + gameScore); gameCounter = (int)(0.5f * gameCounter + 1); //Debug.Log("最高奖"); break; default: break; } if (gameScore > bestScore) { bestScore = gameScore; PlayerPrefs.SetInt("BestScore", bestScore); } if (JavaInterface.Java()) { if (award != 0 && JavaInterface.GetBonus() > (10 * award)) { JavaInterface.AddScorePlayer(award * 10); JavaInterface.CoinOut1Limit(award); //开始退币检查 GameController.isOutCoin = true; Debug.Log("退出" + award + "个币"); } else { Debug.Log("奖金不足无法退出"); } } if (profit >= award) { profit -= award; PlayerPrefs.SetInt("Profit", profit); //Debug.Log("退出"+ award + "个币"); } else { Debug.Log("奖金不足无法退出"); } PlayerPrefs.SetInt("AllScore", allScore); PlayerPrefs.SetInt("GameCounter", gameCounter); PlayerPrefs.Save(); lastScoreText.Display(gameScore, 0.05f); bestText.Display(bestScore); mMainPanel.Award(awards); mMainPanel.Display(); SetGameScore(0); awards = 0; Debug.Log("利润:" + profit + " 第" + gameCounter + "局" + averageScore); } }