void Update() { timer = timer + Time.deltaTime; if (light.intensity < 1) { sprite.color = new Color(1f, 1f, 1f, light.intensity); } else { sprite.color = new Color(1f, 1f, 1f, 1f); } if (touchingLeftWall && touchingRightWall) { sceneManager.GameOver(light.intensity, timer); } if (light.intensity <= 0) { sceneManager.GameOver(light.intensity, timer); } text.SetText("LIGHT: {0:2}", light.intensity); }
IEnumerator OnCollisionEnter2D(Collision2D c) { if (c.gameObject.CompareTag("Obstacle") && health != 0 && !EnemyDeath) //if player hit an obstacle { float sign = GetComponent <Transform>().position.x - c.gameObject.transform.position.x; // get position difference between player and obstacle to see in which direction he hit it float dir = sign / Mathf.Abs(sign); // change the differencethe player to either 1 or -1 rb.AddForce(new Vector2(300 * sign, 300)); // add force according to sign health -= 0.125f; // decrease player health image.fillAmount = health; // change health amount (Image) audio.Play(); // play coins audio // removeCoins(); } if (health == 0 && !isDead) //if player is dead { gameSound.isOver = true; isDead = true; // set player as dead camera.Follow = null; // freeze camera animator.SetTrigger("Dead"); // trigger death animation rb.constraints = RigidbodyConstraints2D.FreezeRotation; //freeze rotation of player rb.constraints = RigidbodyConstraints2D.FreezePositionX; // freeze position of player rb.gameObject.GetComponent <BoxCollider2D>().isTrigger = true; // so that the player rb.gameObject.GetComponent <CircleCollider2D>().isTrigger = true; // doesnt hit the floor yield return(new WaitForSeconds(1)); // wait for 1 sec transition.SetTrigger("End"); // Trigger fade in animation yield return(new WaitForSeconds(2)); gameOver.SetTrigger("gameOver"); yield return(new WaitForSeconds(4)); currentScene = SceneManager.GetActiveScene().buildIndex; SceneManagement.GameOver(); } }
// Update is called once per frame void Update() { //CameraRotation(); //currentPos = whitePiecesSide.transform.position; turnText.text = $"Player Turn: {currentTurn}"; if (numberOfBlackPiecesOnBoard <= 0) { SceneManagement.GameOver(); } else if (numberOfWhitePiecesOnBoard <= 0) { SceneManagement.Win(); } //if(currentTurn==colorTurn.white) //{ // //whitePiecesSide.enabled = true; // //blackPiecesSide.enabled = false; // //whitePiecesSide.transform.RotateAround(Vector3.zero, Vector3.up, degrees); //} //else if (currentTurn == colorTurn.black) //{ // //whitePiecesSide.enabled = false; // //blackPiecesSide.enabled = true; //} }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag.Equals(nameTag)) //Jika tag object yang masuk ke area Trigger adalah sesuai dengan namaTag, { Data.score += 25; //tambah score textScore.text = Data.score.ToString(); //tampilkan score Destroy(collision.gameObject); //hancurkan objek MediaPlayerBenar.Play(); //audio benar keluar } else//jika tag salah { if (Data.score > 0) { Data.score -= 5; //kurangi skor textScore.text = Data.score.ToString(); //tampilkan skore Destroy(collision.gameObject); //hancurkan objek MediaPlayerSalah.Play(); //keluar audio salah } else { Destroy(collision.gameObject); endScene.GameOver(); } } }
public void Die() { //Destroy(m_innerWitch); //Destroy(m_outerWitch); //Destroy(gameObject); GameManager.instance.GameOver(); SceneManagement.GameOver(); }
// Update is called once per frame void Update() { timerText.text = ((int)timer.remainingSeconds).ToString(); hidersFoundText.text = "Hiders Found: " + SceneManagement.hidersFound; //if timer runs out, end game if (timer.remainingSeconds <= 0) { SceneManagement.GameOver(); } }
// Update is called once per frame void Update() { CurrentTime -= Time.deltaTime * timerSpeed; timerText.SetText(CurrentTime.ToString("0")); if (CurrentTime < 0 && !a) { a = true; //Game Over scene.GameOver(); audio.GameOverSound(); } }
public void EndofTurn() { if (population <= minPopulation) { SceneManagement.Victory(); } population = (int)(population * (1 + growthRate)); if (population >= maxPopulation) { SceneManagement.GameOver(); } }
//decrease health if player is hit by enemy private void OnTriggerEnter2D(Collider2D collision) { //decrease health if (collision.gameObject.tag == "Ghost") //if its a ghost //&& collision.gameObject.GetComponent<UnityGhost>()._behaviors != SteeringBehaviors.Seek) //and if its not going to its home location { if (isInvincible == false) { source.PlayOneShot(clip, 0.8f); StatManager.health -= 1; StartCoroutine(Hurt()); StartCoroutine(Invincible()); } if (StatManager.health <= 0) { SceneManagement.GameOver(); } } //pickup key object else if (collision.gameObject.tag == "key") { source.PlayOneShot(clip2, 0.8f); StatManager.hasKey = true; Destroy(collision.gameObject); } //go to next level if player has key else if (collision.gameObject.tag == "stair") { if (StatManager.hasKey) { source.PlayOneShot(clip2, 0.8f); SceneManagement.LevelChange(); StatManager.hasKey = false; } } else if (collision.gameObject.tag == "Exit") { if (StatManager.hasKey) { source.PlayOneShot(clip2, 0.8f); SceneManagement.LevelChange(); StatManager.hasKey = false; StatManager.health = playerHealth; } } }
private void OnTriggerEnter2D(Collider2D collision)//saat triger collider terkena { Data.score = 0; Destroy(collision.gameObject);//menghancurkan object endScene.GameOver(); }