0
votes

Singleton Script:

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


    private void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Destroy(this.gameObject);
        }
        else
        {
            _instance = this;
            DontDestroyOnLoad(this.gameObject);
        }
    }

    public enum Ship
    {
        BasicShip
    };

    public Ship spawnShipID;

Spawner Object

public GameObject basicShip;

void Start()
{
    if (ShipSingleton.Instance.spawnShipID == ShipSingleton.Ship.BasicShip)
    {
        Instantiate(basicShip, transform.position, Quaternion.identity);
    }
}

Button Script

 public Ship ShipID = ShipSingleton.Ship.BasicShip;

    public void shipchoice()
    {

        SceneManager.LoadScene("watcherqueen");
        ShipSingleton.Instance.spawnShipID = ShipID;

    }

Keep getting this error:

Error CS0246 The type or namespace name 'Ship' could not be found (are you missing a using directive or assembly reference?

Is it possible I am missing a reference to the public enum in the button script?

1

1 Answers

1
votes

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;
}