i got error cs1002 ; expected in a c# can someone help me

i tried but it did nothing or break the rules of syntax and cause more errors this is the code

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

public class goal : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
PlayerController component = other gameObject.GetComponent();
if(component != null)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
}

First of all, please use code tags when posting code. There are two buttons in the toolbar, one for adding a block of code and one for inline code snippets.

Second when you get a compiler error, the error tells you the exact line number and even character number in the error. You have not shared that information. The compiler can tell you exactly where the error is. We have now search through your complete code to find the error again. So please include the relevant information next time.

Your error is in this line:

PlayerController component = other gameObject.GetComponent<PlayerController>();

You’re missing a “dot” in between “other” and gameObject. As it’s written right now, with a space, it just makes no sense. The compiler is not an AI that can predict what you actually wanted to do. It just reads what you have written and when it doesn’t make sense it complains about that. Lexically that space makes no sense to the compiler, so it suggests that you may by missing a semicolon which terminates the previous statement. However that’s not what you want. You want

PlayerController component = other.gameObject.GetComponent<PlayerController>();

or just

PlayerController component = other.GetComponent<PlayerController>();

since every component also has a GetComponent method so there’s no need to manually grab the gameobject.

thanks but it made more errors

We can’t quite see your screen from here to read the new errors.

2 Likes

You can fix your own typing mistakes. Here’s how:

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

1 Like

sorry for a month with out a reply the error code was a name of a file i spelled wrong