Code wont work

I get error:
error cs1001 identifier expected

I don’t understand I copied it word for word.

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

public class win : MonoBehaviour

{
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            //Debug.Log("you win");
            SceneManager.LoadScene(0);
        }
    }
}

Hi,

Welcome to our community! :slight_smile:

Unfortunately, I do not know in which course and lecture you are but, given you are following one of our courses, have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?


See also:

Complete C# Unity Game Developer 2D Online Course - 2021

Im on the Snowboarder section
Video: NameSpaces & SceneManagement 7min45secs in.

Code looks right to me.

My guess would be that your class name “win” doesn’t match the file name. On a monobehaviour, if your class name doesn’t match the file name, you’re going to run into issues. Make sure both match and I’d guess you’d be good to go.

Good luck with your learning journey.

They are both the same, I even tried it with a new script with a different name. So is this a Unity bug?

Are there any error messages in your console?

And which exact version of Unity do you use? Quite a few students are experiencing issues with Unity 2021.2. Maybe you could try to downgrade to Unity 2021.1.

There ya go… there’s your error. Should be:

using UnityEngine.SceneManagement;

Nope. Not a bug. It’s a syntax error. None of us picked it up earlier.

Good catch, @MichaelP. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms