Namespace error C#

Hi all,

I would like to know how to fix this error:

Assets/Scripts/GlobalHealth.cs(4,19): error CS0234: The type or namespace name SceneManagement' does not exist in the namespace UnityEngine’. Are you missing an assembly reference?

I can’t seem to fix it! Please help!
Many thanks in advance.

This is the script (it’s purpose is to manage a player’s health):

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class GlobalHealth : MonoBehaviour {
   
    public static int PlayerHealth = 10;
    public int InternalHealth;
    public GameObject HealthDisplay;
   
    void Update () {
        InternalHealth = PlayerHealth;
        HealthDisplay.GetComponent<Text> ().text = "Health: " + PlayerHealth;
        if (PlayerHealth == 0) {
            SceneManager.LoadScene (1);
        }
    }
}

What version of Unity are you on?

Unity 5.1.3f1

You should probably upgrade your Unity! :slight_smile:
If there’s a way to find which version introduced this class, I’m not aware of it. (Like Microsoft docs do with C#) :slight_smile:
That’s an older version, though, so my best guess is that it was not available back then, which @Brathnann was probably curious about.

Here you can look at the older docs :wink:
https://docs.unity3d.com/Manual/ManualVersions.html

and yes it appears the SceneManager was not introduced then:
https://docs.unity3d.com/510/Documentation/Manual/30_search.html?q=SceneManager

Thanks for that :slight_smile: It would be nice if they added "Introduced in … " on doc page :wink:

1 Like

SceneManager was added in 5.3. There are other threads about it. Upgrade to at least 5.3.x and add the import, then things should work normally. I’d get a 2017 version though.

Looks like everyone beat me to it. :slight_smile: But yeah, that was the point I was aiming for.

The older version of Unity used Application.LoadScene, but as mentioned, considering how old 5.1 is, it certainly couldn’t hurt to upgrade your version of Unity.

Thanks so much! This helped me a lot and I am almost done with my game!

If you are almost done, it might make sense to stay where you are and just use the old docs. Version upgrades can get messy. Especially jumping a several years in one go.