I GET THIS ERROR AND I DONT KNOW HOW TO FIX IT

IM TRYING TO WRITE THE WALKING SCRIPT 4 A CHARACTER N I GET HIS SHIT PLS HELP

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour

{
    private float horizontal;
    private float speed = 8f;
    private float jumpingPower = 16f;
    private bool isFacingRight = true;

    [SerializeField] private Rigidbody2D rb;
    [SerializeField] private Transform groundCheck;
    [SerializeField] private LayerMask groundLayer;

     // Update is called once per frame

    void Update()
    {
        horizontal = Input.GetAxisRaw("Horizontal");

        if (Input.GetButtonDown("Jump") && IsGrounded)
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
        }

        if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
        {
            rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
        }

        Flip();
    }

    private void FixedUpdate()
    {
        rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
    }

    private bool IsGrounded()
    {
        return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
    }

    private void Flip()
    {
        if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
        {
            isFacingRight = !isFacingRight;
            Vector3 localScale = transform.localScale;
            localScale.x *= -1f;
            transform.localScale = localScale;
        }
    }
}

IM TRYING TO WRITE THE WALKING SCRIPT 4 A CHARACTER N I GET HIS SHIT PLS HELP

I mean if you want help, you need to actually explain the issue. You cannot just say you get an error, what error are you receiving? Also if the character is not doing exactly what you want, please explain the intended behaviour, and the behaviour that is actually happening. You will unlikely get help on a forum with what you have typed.

1 Like

Mb I’m trying to make my first prototype of a platformer game, I was trying to make the script for the movement by watching this yt video
https://www.youtube.com/watch?v=K1xZ-rycYY8
n it gives me that error n I don’t know how to make it work

the code was the exactly same n the steps but it still doesn’t work

I’ll ask again. What error? I don’t see where you would state what the error is. Did you forgot to copy paste it? Or maybe forum didn’t like how you added it and it got lost.

oh forgot to add it mbmb ,Assets\PlayerMovementOk.cs(23,13): error CS0019: Operator ‘&&’ cannot be applied to operands of type ‘bool’ and ‘method group’ ,

8747352--1184868--upload_2023-1-21_21-26-11.png also i get this under the script

The error message tells where the problem is or at least rough area. \PlayerMovementOk.cs(23,13) means line 23 position 13 . If you clicked on the error in Unity (don’t remember single or double) it should open the corresponding position in editor.

Now go back to tutorial and carefully compare this line with the code in tutorial. Your code is not exactly the same as tutorial. And the compiler is even telling where the problem is so you don’t have to check all of it.

1 Like

You have just made a typo.
On this line if (Input.GetButtonDown("Jump") && IsGrounded) you are using IsGrounded as if it is a straight boolean variable, however it is actually a method and as such you should change the line to be if (Input.GetButtonDown("Jump") && IsGrounded()) which then uses the return value from that method. You can see this at 3:54 in your tutorial video.

That is expected as it is just telling you that this script has an error and you have to fix it before Unity will let you continue work.

Just one other point for the future:
Typing all in caps (which I’m glad to see you stopped doing) is equivalent to yelling on a forum. Some people will immediately start ignoring posts like that as it is not great etiquette.

oh thx, got the problem fixed thx a lot guys !!! appreciate it a lot !!! thx a lot again