void OnTriggerEnter2D(Collider2D objectHit) { if (!isInvincible) { //If it hit a bullet if (objectHit.gameObject.GetComponent <BulletController>()) { //Take damage and check if he died PlayerInformation.GetInstance().DecreasePlayerHealth(); AudioManager.GetInstance().SlimeDamageSound(); //Update UI playerHeartsArray.UpdateUIPlayer(PlayerInformation.GetInstance().health); if (isTaunting) { anim.SetTrigger("PlayerTauntHurtAnimTrigger"); } else { anim.SetTrigger("PlayerStillHurtAnimTrigger"); } //--health; if (PlayerInformation.GetInstance().health <= 0) { Died(); } StartCoroutine(Invincibility()); } } }
/// <summary> /// Starts the game /// </summary> public void ClickPlayButton() { AudioManager.GetInstance().ClickSound(); PauseMenuController.isPaused = false; PlayerInformation.GetInstance().RestartGame(); SceneManager.LoadScene(firstStage); }
void Awake() { // UI playerHeartsArray = GameObject.FindGameObjectWithTag("PlayerHeartsArray").GetComponent <UIComponentPlayerHearts>(); playerHeartsArray.UpdateUIPlayer(PlayerInformation.GetInstance().health); // cache some components transform = GetComponent <Transform>(); circleCollider = GetComponent <CircleCollider2D>(); rigidBody2D = GetComponent <Rigidbody2D>(); // here, we trigger our properties that have setters with bodies skinWidth = _skinWidth; // we want to set our CC2D to ignore all collision layers except what is in our triggerMask for (var i = 0; i < 32; i++) { // see if our triggerMask contains this layer and if not ignore it if ((triggerMask.value & 1 << i) == 0) { Physics2D.IgnoreLayerCollision(gameObject.layer, i); } } }
/// <summary> /// Restarts the game /// </summary> public void ClickPlayAgainButton() { AudioManager.GetInstance().ClickSound(); PlayerInformation.GetInstance().RestartGame(); SceneManager.LoadScene(firstStage); }