how to fix error cs1525 in unity invalid expression term &&

hey im following natty creates tutorial on how to make an fps and unity is throwing invalid expression term && at me here is my code

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

public class PlayerMotor : MonoBehaviour
{
    private CharacterController controller;
    private Vector3 playerVelocity;
    public float speed = 5f;
    public float gravity = -9.8f;
    public string isGrounded;
   
    // Start is called before the first frame update
    void Start()
    {
         controller = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
       isGrounded = controller.isGrounded;
    }


    public void ProccesMove(Vector2 input)
    {
        Vector3 moveDirection = Vector3.zero;
        moveDirection.x = input.x;
        moveDirection.z = input.y;
        controller.Move(transform.TransformDirection(moveDirection)* speed * Time.deltaTime);
        playerVelocity.y += gravity * Time.deltaTime;
        if(isGrounded && playerVelocity.y < 0);
        playerVelocity.y = -2f;
        controller.Move(playerVelocity * Time.deltaTime);
        Debug.Log(playerVelocity.y);
    }
}

The error report the compiler gives you also tells you the line. When asking about errors and posting code, please state which line it is.

In this case, on line 33 above you’re using the && (I assume you know what that means) on a string which you cannot do. I can only presume that you’ve copied code for “isGrounded” and typed “string” rather than “bool” as its type on line 11 above.

1 Like