TakeLife() public method

public TakeLife ( ) : void
return void
Exemplo n.º 1
0
    void OnTriggerEnter(Collider collision)             // used for things like bullets, which are triggers.
    {
        if (damageOnTrigger)
        {
            if (this.tag == "PlayerBullet" && collision.gameObject.tag == "Player")             // if the player got hit with it's own bullets, ignore it
            {
                return;
            }

            if (collision.gameObject.GetComponent <Health>() != null)
            {   //if the hit object has the Health script on it, deal damage
                collision.gameObject.GetComponent <Health>().ApplyDamage(damageAmount);

                if (destroySelfOnImpact)
                {
                    Destroy(gameObject, delayBeforeDestroy);     //destroy the object whenever it hits something
                }

                if (explosionPrefab != null)
                {
                    Instantiate(explosionPrefab, transform.position, transform.rotation);
                }
                else if (collision.gameObject.tag == "Player")
                {
                    lifesystem.TakeLife();
                    gm.ScoreReset();
                }
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (playerHealth <= 0 && !isDead)
        {
            levelManager.RespawnPlayer();
            lifeSystem.TakeLife();
            isDead       = true;
            playerHealth = maxPlayerHealth;
        }

        if (playerHealth > maxPlayerHealth)
        {
            playerHealth = maxPlayerHealth;
        }

        //text.text = "x " + playerHealth;

        healthBar.value = playerHealth;
        //ZWIEKSZANIE HP O 1
        if (increasingHP == false)
        {
            return;
        }
        else
        {
            maxPlayerHealth  = PlayerPrefs.GetInt("PlayerMaxHealth");
            maxPlayerHealth += healthToIncrease;
            PlayerPrefs.SetInt("PlayerMaxHealth", maxPlayerHealth);
            healthBar.maxValue += healthToIncrease;
            increasingHP        = false;
            FullHealth();
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (playerHealth <= 0 && !isDead)
        {
            playerHealth = 0;
            levelManager.ReapawnPlayer();
            lifeSystem.TakeLife();
            isDead = true;
            //theTime.ResetTime();
            Debug.Log("Smierc");

            if (firstDead)
            {
                onelife();
            }
        }

        if (playerHealth > maxPlayerHralth)
        {
            playerHealth = maxPlayerHralth;
        }

        //text.text = "" + playerHealth;
        healthBar.value = playerHealth;
    }
Exemplo n.º 4
0
    //this will reduce player health according to passed int value
    public void HurtPlayer(int damageToGive)
    {
        //redusing player healthBar from method passed value
        playerHelath -= damageToGive;
        //then save it in XML file using key value paires
        PlayerPrefs.SetInt("PlayerCurrentHealth", playerHelath);

        if (playerHelath <= 0 && !isDead)
        {
            playerHelath = 0;
            //reduce one life
            lifeSystem.TakeLife();
            healthBar.value = playerHelath;
            //respawn the player
            levelManager.RespawnPlayer();
            isDead = true;
        }
        else
        {
            if (playerHelath > maxPlayerHealth)
            {
                playerHelath = maxPlayerHealth;
            }
            healthBar.value = playerHelath;
        }
    }
    public IEnumerator RespawnPlayerCo()
    {
        player.rb2dPlayer.constraints = RigidbodyConstraints2D.FreezePositionY;


        theAM = FindObjectOfType <AudioManager>();



        Instantiate(deathParticle, player.transform.position, player.transform.rotation);
        player.enabled = false;
        player.GetComponent <Animator>().enabled         = false;
        player.GetComponent <Rigidbody2D>().velocity     = new Vector2(0, 0);
        player.GetComponent <Rigidbody2D>().gravityScale = 0;
        player.rb2dPlayer.constraints = RigidbodyConstraints2D.FreezeAll;

        yield return(new WaitForSeconds(respawnDelay));

        player.transform.position = currentCheckpoint.transform.position;
        player.GetComponent <Rigidbody2D>().gravityScale = 1;
        player.enabled = true;
        player.GetComponent <Animator>().enabled = true;
        player.rb2dPlayer.constraints            = RigidbodyConstraints2D.FreezeRotation;

        lifeManager.TakeLife();
        theAM.BGM.Play();
        healthManager.FullHealth();
        healthManager.isDead = false;
    }
Exemplo n.º 6
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.name == "MainCh")
        {
            theme.Stop();

            // Respawn player if ontrigger event called
            levelM.Respawn();

            liftManager.TakeLife();

            // game over when lift count <= 0
            if (liftManager.LifeCounter <= 0)
            {
                liftManager.GameOverSound.Play();
                pause.ShowScreenGO();
                Time.timeScale = 0f;
            }
            else
            {
                source.PlayOneShot(sound);
                theme.Play();
            }
        }
    }
Exemplo n.º 7
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         lifeSystem.TakeLife();
     }
     UnityEngine.SceneManagement.SceneManager.LoadScene("Level 10");
 }
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.name == "Player")
     {
         lifeSystem.TakeLife();
         lvlManager.RespawnPlayer();
     }
 }
Exemplo n.º 9
0
 void OnTriggerEnter2D(Collider2D c)
 {
     if (c.name == "Player")
     {
         levelManager.RespawnPlayer();
         lifeSystem.TakeLife();
         ScoreManager.Reset();
     }
 }
Exemplo n.º 10
0
        public void EndGame()
        {
            LifeManager lifeManager = GameObject.FindObjectOfType <LifeManager>() as LifeManager;

            if (lifeManager)
            {
                lifeManager.TakeLife();
            }
        }
Exemplo n.º 11
0
 void Update()
 {
     if (playerHealth <= 0 && !isDead)
     {
         theLevelManager.RespawnPlayer();
         isDead = true; //cosi respawna 1 sola volta
         theLifeManager.TakeLife();
     }
     thisText.text = "Health: " + playerHealth;
 }
Exemplo n.º 12
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.name == "Player")
     {
         lifeSystem.TakeLife();
         kbplayer.knockbackCount = 0;
         levelManager.RespawnPlayer();
         // If this hits player then takes life, knockback is 0 and LevelManger respawnPlayer function starts
     }
 }
Exemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        if (playerHealth <= 0 && !isDead)
        {
            levelManager.RespawnPlayer();
            lifeSystem.TakeLife();
            isDead = true;
        }

        text.text = "" + playerHealth;
    }
Exemplo n.º 14
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.name == "player")
     {
         igralec.transform.position = respawn.position;
         //Destroy(col.gameObject);
         AudioSource.PlayClipAtPoint(zvokDie, transform.position);
         //gameLevelManager.Respawn();
         lifeSystem.TakeLife();
     }
 }
Exemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        if (playerHealth <= 0 && !isDead)
        {
            playerHealth = 0;             //prevents display calculation
            levelManager.RespawnPlayer();
            lifeSystem.TakeLife();
            isDead = true;
//			timeManager.ResetTime();
        }

        text.text = "" + playerHealth;
    }
Exemplo n.º 16
0
    // Update is called once per frame
    void Update()
    {
        if (playerHealth <= 0 && !isDead)
        {
            levelManager.RespawnPlayer();
            isDead       = true;
            playerHealth = 0;
            lifeSystem.TakeLife();                 // 減一條命
        }

        //life_ui.text = playerHealth.ToString();
        healthBar.value = playerHealth;
    }
Exemplo n.º 17
0
 public void RespawnPlayer()
 {
     timer += Time.deltaTime;
     if (timer >= waitTime)
     {
         lifeSystem.TakeLife();
         player.transform.position  = currentCheckpoint.transform.position;
         playerHealth.CurrentHealth = 100;
         timer = 0f;
         playerHealth.HealthSlider.value = playerHealth.CurrentHealth;
         characterMovement.enabled       = true;
         anim.Play("Blend Tree");
     }
 }
Exemplo n.º 18
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "FallDetector")
     {
         AudioSource.PlayClipAtPoint(zvokDie, transform.position);
         gameLevelManager.Respawn();
         lifeSystem.TakeLife();
     }
     if (other.tag == "Checkpoint")
     {
         AudioSource.PlayClipAtPoint(zvokFlag, transform.position);
         respawnPoint = other.transform.position;
     }
 }
Exemplo n.º 19
0
    // Update is called once per frame
    void Update()
    {
        if (playerHealth <= 0 && !isDead)           /*** prevent making player dead for respawn properly***/
//			if (playerHealth <= 0) {
        {
            playerHealth = 0;
            levelManager.RespawnPlayer();

            lifeManager.TakeLife();
            isDead = true;
        }

        //text.text = "" + playerHealth;
        healthSlider.value = playerHealth;
    }
Exemplo n.º 20
0
    // Update is called once per frame
    void Update()
    {
        if (playerCurHealth <= 0)
        {
            playerCurHealth = 0;
            levelManager.RespawnPlayer();
            lifeSystem.TakeLife();
            theTime.ResetTime();
        }

        if (playerCurHealth > maxPlayerHealth)
        {
            playerCurHealth = maxPlayerHealth;
        }
    }
Exemplo n.º 21
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         lifeSystem.TakeLife();
         UnityEngine.SceneManagement.SceneManager.LoadScene("Level 10");
     }
     if (other.gameObject.CompareTag("Barrier"))
     {
         Destroy(other);
     }
     if (other.gameObject.CompareTag("JumpBoost"))
     {
         Destroy(other);
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (playerHealth <= 0 && !isDead)
     {
         playerHealth = 0;
         levelManager.RespawnPlayer();
         lifeSystem.TakeLife();
         isDead = true;
     }
     if (playerHealth > maxPlayerHealth)
     {
         playerHealth = maxPlayerHealth;
     }
     //text.text=""+playerHealth;
     healthBar.value = playerHealth;
 }
Exemplo n.º 23
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.name == "Player")
     {
         livesSystem.TakeLife();
         // if the player triggers the hit box of the spike it'll take away a life from the player
         levelManager.RespawnPlayer();
         // after they die it'll respawn player into the last checkpoint touched
         if (livesSystem.currentLives() == 0)
         {
             Debug.Log('0');
             deathMenu.ToggleMenu();
             control.Done();
             // If lives go to zero the death menu will pop up
         }
     }
 }
Exemplo n.º 24
0
    ///***********************************************************************
    /// Collision detection and management
    ///***********************************************************************
    void OnCollisionEnter(Collision c)
    {
        //collision with mazes and enemyballs leads to a sudden gameover
        if (c.gameObject.tag == "Maze")
        {
            print("Game Over");
            //GameController.gameOver = true;
            Instantiate(explosionPrefab, transform.position, transform.rotation);
            //transform.position = respawnPosition;   // reset the player to respawn position
            //transform.rotation = respawnRotation;
            lifesystem.TakeLife();
        }

        if (c.gameObject.tag == "enemyBall")
        {
            Destroy(c.gameObject);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (playerHealth <= 0 && !isDead)
        {
            playerHealth = 0;
            levelManager.RespawnPlayer();
            lifeSystem.TakeLife();
            isDead = true;
            theTime.ResetTime();
        }

        if (playerHealth > maxPlayerHealth)
        {
            playerHealth = maxPlayerHealth;
        }

        //GetComponent<Text>().text = "" + playerHealth;
        healthBar.value = playerHealth;
    }
Exemplo n.º 26
0
    // Update is called once per frame
    void Update()
    {
        if (playerHealth <= 0 && !isDead)                                                                       // if player is out of health

        {
            playerHealth = 0;
            levelManager.RespawnPlayer();                                                                       // respawn player
            lifeSystem.TakeLife();                                                                              // adjust lifeSystem
            isDead = true;                                                                                      // is dead
        }
        // makes it so player health cannot go greater than max health
        if (playerHealth > maxPlayerHealth)
        {
            playerHealth = maxPlayerHealth;
        }


        healthBar.value = playerHealth;                                                                         // adjust health bar
    }
    void Update()
    {
        if (playerHealth <= 0 && !isDead)
        {
            lifeSystem.TakeLife();
            playerHealth = 0;
            lvlmangr.RespawnPlayer();
            // lifeSystem.TakeLife();
            isDead = true;
            theTime.ResetTime();
        }

        if (playerHealth > maxPlayerHealth)
        {
            playerHealth = maxPlayerHealth;
        }

        healthBar.value = playerHealth;
        // text.text = "" + playerHealth;
    }
Exemplo n.º 28
0
    // Update is called once per frame
    void Update()
    {
        if (healthPlayer <= 0 && !isDead)
        {
            healthPlayer = 0;
            lifeSystem.TakeLife();
            //print ("roi xuong !");
            theTime.ResetTime();
            levelManager.RespawnPlayer();
            //ScoreManager.Reset ();

            isDead = true;
        }
        if (healthPlayer > maxHealthPlayer)
        {
            healthPlayer = maxHealthPlayer;
        }
        //text.text = "" + healthPlayer;
        healthBar.value = healthPlayer;
    }
Exemplo n.º 29
0
    // Update is called once per frame
    void Update()
    {
        if (playerHealth <= 0 && !isDead)
        {
            playerHealth = 0;
            levelManager.RespawnPlayer();
            lifeSystem.TakeLife();
            isDead = true;
            // If player's health is lower than 0 and isDead is false, player's Health is still 0, calls LevelManger RespawnPlayer function, LifeManager's TakeLife Function and isDead is true.
        }
        if (playerHealth > maxPlayerHealth)
        {
            playerHealth = maxPlayerHealth;
            // Player's health will not go over max
        }


        healthBar.value = playerHealth;
        // The value of the health bar links with player's health
    }
Exemplo n.º 30
0
    /*
     * @param spawnPoint, the location where the player is respawned
     * Method called to respawn the player, and re-initializes the Player's beginning state.
     */
    public void RespawnAt(Transform spawnPoint)
    {
        // Handles which direction the player is facing upon Respawn
        if (!_isFacingRight)
        {
            Flip();
        }

        IsDead = false;                             // player is not dead
        GetComponent <Collider2D>().enabled = true; // collider2D.enabled = true;
        _controller.HandleCollisions        = true; // sets collisions to true again
        Health             = MaxHealth;             // sets current health to the Player object's max health
        onLadder           = false;
        onIce              = false;
        onWater            = false;
        Status             = PlayerStatus.Normal;   // sets player status to normal
        transform.position = spawnPoint.position;   // respawns the player at the spawnPoint

        lifeSystem.TakeLife();                      // decrements lives on the LifeManager
    }