Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

error CS0131: The left-hand side of an assignment must be a variable, property or indexer

Discussion in 'Scripting' started by Razzy1199, Nov 7, 2020.

  1. Razzy1199

    Razzy1199

    Joined:
    Jan 25, 2020
    Posts:
    6
    I need help with this error i have been having error CS0131: The left-hand side of an assignment must be a variable, property or indexer(line: 59)i've searched on google couldn't find an answer. What am i doing wrong?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerMovement : MonoBehaviour
    6. {
    7.      public float speed;
    8.      public float jumpForce;
    9.      private float moveInput;
    10.  
    11.     private Rigidbody2D rb;
    12.  
    13.     private bool facingRight = true;
    14.  
    15.     private bool isGrounded;
    16.     public Transform groundCheck;
    17.     public float checkRadius;
    18.     public LayerMask whatIsGround;
    19.  
    20.     private int extraJumps;
    21.     public int extraJumpsValue = 1;
    22.  
    23.     // Start is called before the first frame update
    24.     void Start()
    25.     {
    26.         extraJumps = extraJumpsValue;
    27.         rb = GetComponent<Rigidbody2D>();
    28.     }
    29.  
    30.     // Update is called once per frame
    31.     void FixedUpdate()
    32.     {
    33.         isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
    34.  
    35.  
    36.  
    37.         moveInput = Input.GetAxisRaw("Horizontal");
    38.         Debug.Log(moveInput);
    39.         rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
    40.  
    41.         if(facingRight == false && moveInput > 0 ){
    42.           Flip();
    43.  
    44.         }else if(facingRight == true && moveInput < 0){
    45.             Flip();
    46.         }
    47.  
    48.     }
    49.     void Update(){
    50.      
    51.         if(isGrounded == true){
    52.             extraJumps = extraJumpsValue;
    53.         }
    54.  
    55.         if(Input.GetKeyDown(KeyCode.Space) && extraJumps > 0){
    56.         extraJumps--;
    57.         rb.velocity = Vector2.up * jumpForce;
    58.         }
    59.         else if(Input.GetKeyDown(KeyCode.Space) && extraJumps == 0 && isGrounded = true){
    60.          rb.velocity = Vector2.up * jumpForce;
    61.         }
    62.     }
    63.  
    64.     void Flip(){
    65.  
    66.         facingRight = !facingRight;
    67.         Vector3 Scaler = transform.localScale;
    68.         Scaler.x *= -1;
    69.         transform.localScale = Scaler;
    70.     }
    71. }
    72.  
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Pretty sure you meant == true instead of = true in line 59. Also, isGrounded == true is the same as just isGrounded. And isGrounded == false is the same as !isGrounded. There is no need to compare a bool to a (hardcoded) bool.
    So you may as well just write && isGrounded there
     
  3. Razzy1199

    Razzy1199

    Joined:
    Jan 25, 2020
    Posts:
    6
    Thanks