Syntax error, expression expected

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

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.

1 Like

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;
}
}

}

9110896–1263493–1111111.cs (597 Bytes)

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.

1 Like

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.