Error CS0246 Type or namespace name could not be found when using enum

后端 未结 1 1526
無奈伤痛
無奈伤痛 2021-01-27 14:47

Singleton Script:

 public static ShipSingleton Instance { get { return _instance; } }


    private void Awake()
    {
        if (_instance != null && _i         


        
相关标签:
1条回答
  • 2021-01-27 15:47

    Oh, I see what the problem is now (and I'll fix it in the other question too) --

    This line needs to reference ShipSingleton.Ship instead of just Ship:

    public Ship ShipID = ShipSingleton.Ship.BasicShip;
    

    So it should look like this:

    public ShipSingleton.Ship ShipID = ShipSingleton.Ship.BasicShip;
    

    This is because the enum type Ship is a member of ShipSingleton. It would not be necessary if Ship were declared at the namespace level like this:

    public enum Ship
    {
        BasicShip
    };
    
    public class ShipSingleton
    {
        public static ShipSingleton Instance { get { return _instance; } }
    
    
        private void Awake()
        {
            if (_instance != null && _instance != this)
            {
                Destroy(this.gameObject);
            }
            else
            {
                _instance = this;
                DontDestroyOnLoad(this.gameObject);
            }
        }
    
        Ship spawnShipID;
    }
    
    0 讨论(0)
提交回复
热议问题