Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

"Assets\Scripts\NoteAppear.cs(4,21): error CS1026: ) expected" don't know how to fix.

Discussion in 'Getting Started' started by Simas01, Dec 13, 2020.

  1. Simas01

    Simas01

    Joined:
    Oct 10, 2020
    Posts:
    14
    Hi all!
    recently i've started seriously trying to make a game with *some* sucess. But im trying to make a sort of a note system, where you walk into a trigger and a note appears on the screen. but after i made the script i get that error and this one too:

    "Assets\Scripts\NoteAppear.cs(4,21): error CS1003: Syntax error, '(' expected"

    any and all help is apreciated below is the script and the video tutorial i followed:



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    Using UnityEngine.UI;

    public class NoteAppear : MonoBehaviour
    {
    [SerializeField]
    private Image _noteImage;


    void OnTriggerEnter(Collider other)
    {
    if (other.CompareTag("Player"))
    {
    _noteImage.enabled = true;
    }
    }
    void onTriggerExit (collider other)
    {
    if (other.CompareTag("Player"))
    {
    _noteImage.enabled =false;
    }
    }

    }
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    The error is telling you that a "(" is expected on line 4 (somewhere around column 21). However a compiler's expectations can be not very helpful sometimes, so just take it as "I don't know what's going on here with line 4."

    So look at line 4. (Note: we could see line numbers here if you used the "Code:" tool in the editing toolbar to insert code properly into your post.)

    Anyway, study the fourth line. Remember that C# is case-sensitive. What's wrong with it?
     
    Joe-Censored and Schneider21 like this.
  3. Simas01

    Simas01

    Joined:
    Oct 10, 2020
    Posts:
    14
    thanks! the "Using" was the wrong bit and the script is done! thank you for the help!
     
    Joe-Censored and JoeStrout like this.
  4. Tahrim09

    Tahrim09

    Joined:
    Jan 12, 2022
    Posts:
    1
    Hi,
    I have recently start this and facing this error

    Assets\scripts\PlayerMovement.cs(41,10): error CS0161: 'PlayerMovement.IsGrounded()': not all code paths return a value

    Here is the script:


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

    public class PlayerMovement : MonoBehaviour
    {
    Rigidbody rb;
    [SerializeField] float movementSpeed = 6f;
    [SerializeField] float jumpForce = 5f;

    [SerializeField] Transform groundCheck;

    [SerializeField] LayerMask ground;

    // Start is called before the first frame update

    void Start()
    {
    Debug.Log("Hello from Start");
    rb = GetComponent<Rigidbody>();

    }

    // Update is called once per frame

    void Update()
    {
    float horizontalInput = Input.GetAxis("Horizontal");
    float verticalInput = Input.GetAxis("Vertical");

    rb.velocity = new Vector3(horizontalInput * movementSpeed, rb.velocity.y, verticalInput * movementSpeed);


    if (Input.GetButtonDown("Jump") /*&& IsGrounded()*/)
    {
    rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
    }

    }

    bool IsGrounded()
    {
    Physics.CheckSphere(groundCheck.position, .1f, ground);
    }
    }



    Why is it happening please let me know about it, Thankyou.
     
  5. jbnlwilliams1

    jbnlwilliams1

    Joined:
    May 21, 2019
    Posts:
    267
    Please start your own thread and use code tags.
     
  6. ELIP4444

    ELIP4444

    Joined:
    Feb 10, 2022
    Posts:
    1
    I have a problem :

    MY ERROR :
    Assets\Scripts\PlayerMouvement.cs(22,70): error CS1061: 'Vector3' does not contain a definition for 'velocity' and no accessible extension method 'velocity' accepting a first argument of type 'Vector3' could be found (are you missing a using directive or an assembly reference?)

    MY CODE :
    using UnityEngine;

    public class PlayerMouvement : MonoBehaviour
    {
    public float moveSpeed;

    public Rigidbody2D rb;
    private Vector3 velocity = Vector3.zero;



    void FixedUpdate()
    {
    float horizontalMouvement = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;

    MovePlayer(horizontalMouvement);
    }

    void MovePlayer(float _horizontalMouvement)
    {
    Vector3 targetVelocity = new Vector2(_horizontalMouvement, rb.velocity.y);
    rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity.velocity, ref velocity, .05f);
    }
    }

    Help me, please :(