Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Syntax error, expression expected

Discussion in 'Code Editors & IDEs' started by Khiladi_Camp, Jun 28, 2023.

  1. Khiladi_Camp

    Khiladi_Camp

    Joined:
    Jun 28, 2023
    Posts:
    2
    On 26/06/2023 unity is working well but on next day if i modify any of my script it says syntax error and expression expected but I have that that expression on that place and if i delete that expression and again writing or add that expression double, still can't fix the error. And if i delete the modified text then no error. Tell me how i solve this
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,556
    We can't read your screen from here.

    Post the code for that part of the file, inside code tags. Post the complete error message.
     
    MelvMay likes this.
  3. Khiladi_Camp

    Khiladi_Camp

    Joined:
    Jun 28, 2023
    Posts:
    2
    Here is the error details..........
    1. Assets\SCRIPTS\InteractableObject.cs(19,18): error CS1026: ) expected
    2. Assets\SCRIPTS\InteractableObject.cs(19,38): error CS1002: ; expected
    3. Assets\SCRIPTS\InteractableObject.cs(19,38): error CS1513: } expected
    4. Assets\SCRIPTS\InteractableObject.cs(27,19): error CS1026: ) expected
    5. Assets\SCRIPTS\InteractableObject.cs(27,39): error CS1002: ; expected
    6. Assets\SCRIPTS\InteractableObject.cs(27,39): error CS1513: } expected

    and code is.......

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

    public class InteractableObject : MonoBehaviour
    {
    public bool playerInRange;


    public string ItemName;

    public string GetItemName()
    {
    return ItemName;
    }

    private void OnTriggerEnter(Collider other)
    {
    if (other CompareTag("Player"))
    {
    playerInRange = true;
    }
    }

    private void OnTriggerExit(Collider other)
    {
    if (other CompareTag("Player"))
    {
    playerInRange = false;
    }
    }

    }
     

    Attached Files:

  4. tleylan

    tleylan

    Joined:
    Jun 17, 2020
    Posts:
    692
    It would help if you posted code within CODE tags. What does if(other CompareTag("Player")) intended to do I've never seen this syntax.
     
    halley likes this.
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,556
    In each error message, the (19,18) part is telling you the line number and approximate column of the error. So there are six errors, but they're just on just two lines.

    if (other.CompareTag("Player"))


    See the extra dot that joins between
    other
    and
    CompareTag
    ?

    If you're following a tutorial, every character matters and needs to be typed accurately exactly as shown. You learn the meanings of each as you go.