Stop Attacking Already - Lecture

Any questions or comments regarding this lecture?

This lecture doesn’t seem to be on my list of videos?

@skiddeh I believe the phrase is “Soon™”

Fair enough, could have sworn I saw it on my list of videos this morning haha

These are not the droids (cough) videos you were looking for… Im sure it will be there soon

Sorry guys, I found an issue in the video so did a sneaky unpublish before too many people dove in. I’m going to publish it again in a moment.

1 Like

So i cant tell if i missed something or not much was explained about the bool. 2 lectures ago i had basically done everything that made the character stop attacking etc and i come to compare my code to the lecture and 1.) maybe its my lack of coding thats not helping me understand how the public bool works with the return 2.) i went and tried to put the same exact code in as shown in the video and im getting errors for using the same name (isDead) so many times which im still wondering how you got away with in the lecture. Here is the code explaining that.
My Code that works

namespace RPG.Combat
{
    public class Healths : MonoBehaviour
    {       
        public float Health = 100f;

        public bool isAlive = true;
             
        public void TakeDamage(float damage)
        {
            Health = Mathf.Max(Health - damage, 0);
            if (Health == 0)
            {
                Die();
            }

        }

        private void Die()
        {
            
            isAlive = false;
            GetComponent<Animator>().SetTrigger("died");  
        }
    }
}
private void Update()
        {
            //timeSinceLastAttack += Time.deltaTime;
            timeSinceLastAttack += Time.deltaTime;

            if (target == null) return;
            if (target.isAlive == false) return;

This is me Changing my code to the lecture

namespace RPG.Combat
{
    public class Healths : MonoBehaviour
    {       
        public float Health = 100f;

        bool isDead = false;
        
        public bool isDead()
        {
            return isDead;
        }

        public void TakeDamage(float damage)
        {
            Health = Mathf.Max(Health - damage, 0);
            if (Health == 0)
            {
                Die();
            }

        }

        private void Die()
        {

            isDead = true;
            GetComponent<Animator>().SetTrigger("died");  
        }
    }
}
    ```
    private void Update()
    {
        //timeSinceLastAttack += Time.deltaTime;
        timeSinceLastAttack += Time.deltaTime;

        if (target == null) return;
        if (target.isDead()) return;
        ```

this is a screenshot of the errors


so what i now did was change the name of the method and it works. So id like to know if i need to have my code like yours where both the method and the bool are the same name because unity isnt allowing me to use multiple names or am i supposed to use a different name for my bool and method?

how did no one respond to you almost a year ago?

lol the answer is that you named your method exactly the same as your bool variable both named isDead you should name the bool variable isDead then name the method IsDead, notice that the “i” is capitalized on the method to differentiate them. variables always start with a lower case and methods always start capitalized to prevent this issue from happening.

Can’t we just call Cancel() method in Fighter when the enemy is dead?