blanshar33
blanshar33

Reputation: 35

The type or namespace name 'Scene' could not be found

It's my first time asking a question here. I started programming in UNITY 3D just recently, so my question can be very common, but I really can't find any answers to it.

I'm watching a tutorial on YouTube and copying the same code. Everything is the same as in the video, but the author doesn't have any problems with it, while I have, I checked the code 10 times, and here is the problem in the question title.

Thank you in advance for your support!

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


public class GameManager : MonoBehaviour
{
    public static GameManager instance;
    private void Awake()
    {
        instance = this;
    }
    // Resourses 
    public List<Sprite> playerSprites;
    public List<Sprite> weaponSprites;
    public List<int> weaponPrices;
    public List<int> xpTable;

    // References

    public Player player;

    //private weapon weapon...

    //Logic
    public int pesos;
    public int experience;

    // SaveState
    /*
     * INT preferedSkin
     * INT pesos
     * INT experience
     * INT weaponLevel
     *
     */
    public void SaveState()
    {
        string s = "";
        
        s += "0" + "|";
        s += pesos.ToString() + "|";
        s += experience.ToString() + "|";
        s += "0";

        PlayerPrefs.SetString("SaveState", s);
    }
    public void LoadState(Scene s, LoadSceneMode mode)
    {
        if(!PlayerPrefs.HasKey("SaveState"))
        {
            return;
        }
        
        string[] data = PlayerPrefs.GetString("SaveState").Split('|');
        
        // Change player skin
        pesos = int.Parse(data[1]);
        experience = int.Parse(data[2]);
        // Change the weapon Level
        
        Debug.Log("LoadState");
    }
}

Upvotes: 1

Views: 719

Answers (3)

Spark
Spark

Reputation: 37

You can either use the "fully qualifying namespace" as such

public void LoadState(UnityEngine.SceneManagement.Scene s, LoadSceneMode mode)

or import the library by including using UnityEngine.SceneManagement; at the top which you can easily access in Visual Studio by Holding down CTRL and pressing ( . ) and it's usually the first option but make sure first that your curser is resting on the erroneous part of the code

Upvotes: 0

dimitar.d
dimitar.d

Reputation: 653

You are missing a package reference. A google search tells me that Scene class is implemented in UnityEngine.CoreModule so try adding it at the top:

using UnityEngine.CoreModule

If you are using Visual Studio you can place the cursor on Scene and hit crtl + . for suggestions.

Upvotes: 0

mlb6300
mlb6300

Reputation: 66

Scene is apart of the the SceneManagment namespace. Try adding:

using UnityEngine.SceneManagement;

source: https://docs.unity3d.com/ScriptReference/SceneManagement.Scene.html

Upvotes: 2

Related Questions