Esempio n. 1
0
 public void TakeDamage(int damage)
 {
     health -= damage;
     onDamaged.Invoke(health);
     if (health < 1)
     {
         onDie.Invoke();
     }
 }
 public void TakeDamage(int damage)
 {
     health -= damage;
     onDamaged.Invoke(health);
     if (health < 1)
     {
         onDie.Invoke();
         if (player == null)
         {
             Destroy(gameObject);
         }
     }
     if (player != null)
     {
         InvokeRepeating("regen", 4, 50);
     }
 }
Esempio n. 3
0
 public void OnDamaged()
 {
     OnDamagedEvent?.Invoke();
     foreach (var handler in handlers)
     {
         handler.OnDamaged();
     }
 }
Esempio n. 4
0
 public void TakeDamage(int damage)
 {
     hp -= damage;
     onDamaged.Invoke(hp);//takes dmg
     if (hp < 1)
     {
         onDie.Invoke();//oof
     }
 }
Esempio n. 5
0
 public void TakeStealth(int damage)
 {
     Stealth -= damage;
     onDetect.Invoke(Stealth);
     if (Stealth < 1)
     {
         onDectected.Invoke();
     }
 }
Esempio n. 6
0
 public void TakeDamage(int damage)
 {
     health -= damage;
     onDamaged.Invoke(health);
     if (health < 1)
     {
         onDie.Invoke();
         Destroy(gameObject);
     }
 }
    public void TakeDamage(int damage)
    {
        health -= damage;
        onDamaged.Invoke(health);


        damageIndicator();


        if (health == 0)
        {
            onDie.Invoke();
        }
    }
Esempio n. 8
0
    public void TakeDamage(int damage)
    {
        //reduces health by damage quantity
        health -= damage;

        //invoke ondamaged with updated health
        onDamaged.Invoke(health);
        //if health is zero or fewer
        if (health < 1)
        {
            //if there's no health, die
            onDie.Invoke();
        }
    }
Esempio n. 9
0
    public void TakeDamage(int damage)
    {
        Health -= damage;

        onDamaged.Invoke(Health);

        if (Health < 1)
        {
            onDie.Invoke();
        }
        else if (Health > 100)
        {
            Health = 100;
        }
    }
Esempio n. 10
0
    //Creates a method that changes the health value and will destroy the game object if it runs out of health
    public void TakeDamage(int damage)
    {
        health -= damage;

        TakenDamage = true;

        onDamage.Invoke(health);

        if (health < 1)
        {
            Vector3 rotationInDegrees = transform.eulerAngles;

            Quaternion rotationInRadians = Quaternion.Euler(rotationInDegrees);
            Instantiate(playerBody, transform.position, rotationInRadians);



            onDie.Invoke();
        }
    }
Esempio n. 11
0
    // When the player takes damage, reduce health
    // and allow onDie.
    public void TakeDamage(int damage)
    {
        health -= damage;
        onDamaged.Invoke(health);
        playerAudioSource.PlayOneShot(takenDamage, 0.25f);

        if (health < 1)
        {
            if (hasPlayedDeathSound == false)
            {
                playerAudioSource.PlayOneShot(die, 0.25f);
                hasPlayedDeathSound = true;
            }

            if (hasPlayedDeathSound == true)
            {
                onDie.Invoke();
            }
        }
    }
Esempio n. 12
0
    /*************************************
    *
    * PUBLIC METHODS
    *
    *************************************/

    /*
     * TakeDamage
     * this public method is called by other GameObjects, like the bullet.
     * when a bullet intersects with the Collider2D on this GameObject, the bullet will
     * use SendMessage to run this method, giving it an amount of damage.
     * TakeDamage will then remove the damage given by the bullet and send and event updating the health
     * value and dying if the health is less than 1
     */
    public void TakeDamage(int damage)
    {
        /*
         * REMOVE THE DAMAGE FROM THE CURRENT HEALTH
         * here we minus the damage given by the TakeDamage method's "damage" parameter
         * giving us a new value for our health
         */
        health -= damage;


        /*
         * SEND THE onDamaged CUSTOM EVENT
         * here we use the Invoke method on the custom event and give it our current health value.
         * We can use this to update other GameObject that may want to know about our GameObjects's health
         * like a health bar.
         * see link: https://docs.unity3d.com/Manual/UnityEvents.html
         * see link: https://docs.unity3d.com/ScriptReference/Events.UnityEvent_1.html
         */
        onDamaged.Invoke(health);


        /*
         * CHECK IF health IS LESS THAN 1
         * If our new health value is less than 1, send the onDie event
         */
        if (health < 1)
        {
            /*
             * SEND THE onDie EVENT
             * here we use the Invoke method and give it no parameters.
             * onDie is a standard UnityEvent, which have no parameters to send.
             * We can use this in the Editor to destroy the GameObject, or activate
             * an animation etc.
             * see link: https://docs.unity3d.com/Manual/UnityEvents.html
             * see link: https://docs.unity3d.com/ScriptReference/Events.UnityEvent.html
             */
            onDie.Invoke();
        }
    }
Esempio n. 13
0
    //used to subtract the damage amount from health
    public void TakeDamage(int damage)
    {
        //subtracts the value of damage from health
        health -= damage;

        //invoke the onDamaged event with the value of health
        if (health > 0)
        {
            onDamaged.Invoke(health);
        }



        //destroys the game object if the health drops below 1
        if (health < 1 && dead == false)
        {
            dead = true;
            onDie.Invoke();
        }

        //updates the health
        updateHealth();
    }