I can't figure out how to use Debug.Log (Unsolved)

I was told in a tutorial to use debug in a jump code to see if it activates when the character is moving right because right now it only works moving left.
But I don’t know how to code the debug.log?
This thing has always confused me because there are different ways to code it depending on the situation.

Debug.Log() simply prints something to the console. What it prints depends on what you pass into the parentheses.
You can use it to print the value of a variable to make sure it’s the correct value you’re expecting, or simply print any random thing just to see if your script is even reaching that line while it’s executing.

Here’s a common example,
you want to destroy the player object when it comes in contact with another object, so you setup your collision logic like so:

void OnCollisionEnter(Collision collision)
{
  if(collision.gameObject.CompareTag("player"))
  {
    Destroy(collision.gameObject);
  }
}

You add this script to some hazard that the player should avoid, and test to see if it works by running the player into it, but you find that nothing happens.

The first thing you can do is check if OnCollisionEnter is even executing by adding a log at the beginning of the method:

void OnCollisionEnter(Collision collision)
{
  //If this prints to the console, then we know the collision detection works.
  Debug.Log("A collision was detected!");

  if(collision.gameObject.CompareTag("player"))
  {
    Destroy(collision.gameObject);
  }
}

You retry the test and notice that nothing prints to the console when the player touches the hazard. This should tell you that something is wrong with your physics colliders, as the collision is not being detected.

You eventually find out that you just forgot to add a collider to the hazard object this script is attached to, so you add the collider, retry the test again, and you see “A collision was detected!” printed to the console, but the player was still not destroyed.
This time, you know it’s not a problem with your colliders; the collision detection did work, so now it’s an issue with the collision logic.

You know that you only want to destroy the player object specifically, and not any random object that touches this hazard, which is why you’re checking if(collider.gameObject.CompareTag("player")) to make sure the object that was collided with has the “player” tag… but does it actually have the “player” tag?
That’s another thing you can check by logging it:

void OnCollisionEnter(Collision collision)
{
  //If this prints to the console, then we know the collision detection works.
  Debug.Log("A collision was detected!");

  //This will print the tag of the object that was collided with for us to see if it's correct.
  Debug.Log(collision.gameObject.tag);

  if(collision.gameObject.CompareTag("player"))
  {
    Destroy(collision.gameObject);
  }
}

You run the test once again and see the following messages printed to the console:

"A collision was detected!"
"Player"

The player object is tagged as “Player”, with a capital ‘P’, not “player”, which is what is being compared.
So you fix the logic to check for the correct tag…

void OnCollisionEnter(Collision collision)
{
  if(collision.gameObject.CompareTag("Player"))
  {
    Destroy(collision.gameObject);
  }
}

…Run the test again, and this time, the player was destroyed as expected.

So in this example, you’ve used Debug.Log() to first check if the code was executing, and also to check if the value of something is correct.

Thanks for the explanation but it didn’t help, because I not realize I have know idea where or what to test for.
The Problem is that the character won’t jump when moving right. If moving left or standing still it will jump. I have reviewed the code and I feel I understand it. So I am at a loss because no where in the code do I see a part that would dictate which direction the character could run in or not.
If someone could please look at the code I think you will see what I am talking about. I don’t see any part in the if statements that would differentiate between moving right or left that could cause this.

public class PlayerCon : MonoBehaviour
{
    private Rigidbody2D myRigidbody;
    private Animator myAnimator;

    [SerializeField]
    private float movementSpeed;

    private bool facingRight;
    private bool attack;
    private bool slide;

    private bool jump;

    [SerializeField]
    private float jumpForce;

    [SerializeField]
    private bool airControl;

    [SerializeField]
    private float groundRadius;

    [SerializeField]
    private LayerMask whatIsGround;

    [SerializeField]
    private Transform[] groundPoints;
    // the [] at the end indicates we want to use an array.

    private bool isGrounded;

    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
        myAnimator = GetComponent<Animator>();
        facingRight = true;
    }

    private void Update()
    {
        HandleInput();
        // Use Regular Update to call this because it needs to be done every frame.

        if (slide && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("NinjaManSlide"))
        {
            myAnimator.SetBool("slide", true);
        }
        else if (!this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("NinjaManSlide"))
        {
            myAnimator.SetBool("slide", false);
        }
    }

    void FixedUpdate()
    {
        float horizontal = Input.GetAxis("Horizontal");

        isGrounded = IsGrounded();

        HandleMovement(horizontal);
        // Adding horizontal passes on the value of the float horizontal.
        Flip(horizontal);

        HandleAttacks();

        ResetValues();

      
    }

    private void HandleMovement(float horizontal)
        // Adding float horizontal between the () defines the parameter horizontal. This way the
    {
        if (!myAnimator.GetBool("slide") && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack"))
        {
            myRigidbody.velocity = new Vector2(horizontal * movementSpeed, myRigidbody.velocity.y);
        }

        if (isGrounded && jump)
        {
            isGrounded = false;
            myRigidbody.AddForce(new Vector2(0, jumpForce));

        }
           
        myAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }

    private void HandleAttacks()
    {
        if (attack && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack"))
        {
            myAnimator.SetTrigger("attack");
            myRigidbody.velocity = Vector2.zero;
        }
    }

    private void HandleInput()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            jump = true;
        }

        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            attack = true;
        }

        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            slide = true;
        }

    }

    private void Flip(float horizontal)
    {
        if (!myAnimator.GetBool("slide"))
            {

            if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight)
            {
                facingRight = !facingRight;

                Vector3 theScale = transform.localScale;
                theScale.x *= -1;
                transform.localScale = theScale;
            }
        }
    }

    private void ResetValues()
    {
        attack = false;
        slide = false;
        jump = false;
    }

    private bool IsGrounded()
    {
        if (myRigidbody.velocity.y <= 0)
            //If Y velocity is less than zero, we are falling, if equal to zero check if
            //we are touching the ground.
        {
            foreach (Transform point in groundPoints)
            {
                Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, whatIsGround);

                for (int i = 0; i < colliders.Length; i++)
                {
                    if (colliders[i].gameObject != gameObject)
                        // Coded so if the game object it colliding with anything but itself.
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}

@MasterElement I still don’t see any Debug.Log statements in your code, place them everywhere. Before your If statements, inside them, and after. You mention “I don’t see any part…”, how about this?

facingRight = true;

This may help with Debug.Log to print out the variable values at runtime:

Thanks that help, unfortunately I’m having an issue. When ever time I enter Degub.log code, either I get an error or the console doesn’t tell me what I programmed it to.
I used this code in my script.

Debug.Log("isGrounded =" + isGrounded.ToString()) ;

IsGtounded is a bool if that matters
And it’s didn’t tell my anything in the console, I have run into this issue several times, even though I’m copying what others in tutorials due and still nothing. I’m getting really frustrated because I keep hitting road blocks on the simplest of coding tasks.

If the console is, in general, not displaying anything at all, then you may have disabled displaying logs.
In the console window, you’ll find these icons:
7960401--1020309--upload_2022-3-13_10-43-30.png
Clicking on them will toggle displaying logs/warnings/errors.

You were right Vryken I filddled with the console a little while ago.
I think I figured out the cause of the problem just not where it’s occurring in the script. Apparently when the character runs to the right isGrounded becomes false even if the character is still on the ground. So the controller thinks the character is already in the air, which mean of course it can’t jump