C# Class confusion

So i have several scripts but I ran into a problem where for some reason I can’t see the scripts.
Eg.:
I have GameManager:

public class GameManager : MonoBehaviour
{

Which I can’t see from inventory:

public class Inventory : MonoBehaviour
{

Why?

Thanks in advance!

1: The class is nested, in which case you’ll have to see ContainerClass.ContainedClass.
2: The class is in a different namespace. Solution same as above or “using Namespace” at top.
3: Restart Unity / the editor you use- sometimes it just happens inexplicably.

Also make sure all of the scripts are saved and that there are no errors.

Do you have any compiler errors? Compiler errors can break autocomplete.

  • I don’t have compile errors
  • Tried restarting unity

Could you give me some example for nested class because the MSDN guide is very confusing for me. Thanks.

Are you trying to access a static member? Have you declared any static members?

I want to Inventory’s:

    [SerializeField]
    public List<Item> ItemsInInventory = new List<Item>();

To always equal to:

public class GameManager : MonoBehaviour
{
    private static GameManager _instance;
    public List<Item> Inventoryitems = new List<Item>();

I don’t think the list being empty would be a possibility, as it would still have the normal object-inherited static methods like Equals()…

A nested class is just a class that’s defined within another class (also called an “inner class”), for instance:

public class SomeContainer
{
    public class SomeContained
    {
     
    }
}

In a case like this, in order to access SomeContained, you have to do so with SomeContainer.SomeContained. It’s important to note that other than the naming convention, there’s little practical correlation between the two. A SomeContained class created from within the SomeContainer class isn’t going to have any knowledge of the SomeContainer class that it wouldn’t always have if it weren’t nested. Doing things this way is purely organizational, unless you make the inner class private, in which case the outer class is the ONLY class that can utilize it.

Valid point.

You don’t have to use autocomplete. Just type the member out in full and compile. If something is wrong there will be a compile error to play with.

Side-stepping the problem for a moment, is there a reason you need two different lists of references to the same set of items? You can copy the reference itself by simply assigning one list to the other, then you’ll have two access points to the same list and won’t have to manually sync them.

Sure you don’t mean public static, not private static?

Does the GameManager class have any public static members? If not you’ll need an instance of it to access any members, or you need to make some members static instead.

@DonLoquacious I have a GameObject with a script GameManager which is a singleton and i want to keep all my data in it.
@GroZZleR In the GameManager? No, I’m pretty sure it won’t change anything… I tried it. No, but if you can tell my anything how it could help i would be very happy.
@Kiwasi There is error.

@Munchy2007
In nearlly all of my scripts i do the following:

public GameManager manager;
void Start()
{
manager = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameManager>();
//So i can
manager.dead == true;
}

can you post the whole GameManager script?

And does it have an error code and line number?

@Kiwasi simply parsing error.

@Munchy2007 once I get home I will.

@Munchy2007 @Kiwasi @DonLoquacious @GroZZleR Here it is:

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

public class GameManager : MonoBehaviour
{
    private static GameManager _instance;
   
    public string Quest;
    public DateTime LastLogin;

   
    public int player_money;
    public int Player_damage;
    public int player_xp;
    public int xp_req;
    public int player_armor;
    public int player_health;
    public int player_potions;
    public int player_armorpen;
    public int player_level;
    public int boosterpacks;
    public int player_base_health;
    public float player_xp_modifier;
    public string player_name;
    public bool dead;
    public bool showinventory;

    public List<Item> Inventoryitems = new List<Item>();

    public Saver ment;
    public Sitelock locker;
    //public List<Item> Inventory;
    public API ka;
   
    public static GameManager instance
    {
        get
        {
            if(_instance == null)
            {
                _instance = GameObject.FindObjectOfType<GameManager>();
               
                //Tell unity not to destroy this object when loading a new scene!
                DontDestroyOnLoad(_instance.gameObject);
            }
           
            return _instance;
        }
    }
   
    void Awake()
    {
        ka = gameObject.AddComponent<API>();
        if(_instance == null)
        {
            //If I am the first instance, make me the Singleton
            _instance = this;
            DontDestroyOnLoad(this);
        }
        else
        {
            //If a Singleton already exists and you find
            //another reference in scene, destroy it!
            if(this != _instance)
                Destroy(this.gameObject);
        }
        ment = gameObject.AddComponent<Saver>();
        ka.Connect();
        ment.StartSave();
    }
}

I copied your code, and created snippets for all of the classes. This works:

GameManager.instance.name = "I Do Exist, Trust me!"

Either your IDE is broken, or you’ve got the manager in a folder that compiles later than where you’re trying to use it - which seems unlikely.

If I make a new script it works in it.
I don’t understand for some scripts it works for some it doesn’t.