Help required, error CS0131

Hi I am having some issues with the unity editor.
Im trying to make a 2d platformer and when I added jumping I got the error “CS0131”
Could someone tell me where the issue is?

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

public class NewBehaviourScript : MonoBehaviour
{
    public float moveSpeed = 10f;
    [SerializeField] private bool isGrounded = false;

    // Start is called before the first frame update
    void Start()
    {
       
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Ground"))
            isGrounded = true;
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.CompareTag("Ground"))
            isGrounded = false;
    }


    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.LeftArrow))
            transform.Translate(new Vector3(-2, 0, 0) * moveSpeed * Time.deltaTime);

        if (Input.GetKey(KeyCode.RightArrow))
            transform.Translate(new Vector3(2, 0, 0) * moveSpeed * Time.deltaTime);

        if (Input.GetKeyDown("space") && isGrounded = true)
        {
            GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
        }

    }
}

Line 38:
if (Input.GetKeyDown(“space”) && isGrounded = true)

isGrounded == true

it needs 2 = as one = is for asigning a value.

1 Like

Just to further explain, in C# a single = basically means “assign to the left side whatever is on the right side”. A double == means “are the two sides equal, true or false?” When your line starts with “if” you use double ==.

Thank you both!!

Remember: NOBODY memorizes error codes. The code is the least useful part of the error.

The important part is the description of the error itself, the file it occurred in, and the line number and character position.

All of that information is in the actual error message and you must pay attention to it.

How to understand compiler and other errors and even fix them yourself: