单例脚本:
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;
生成器对象
public GameObject basicShip;
void Start()
{
if (ShipSingleton.Instance.spawnShipID == ShipSingleton.Ship.BasicShip)
{
Instantiate(basicShip, transform.position, Quaternion.identity);
}
}
按钮脚本
public Ship ShipID = ShipSingleton.Ship.BasicShip;
public void shipchoice()
{
SceneManager.LoadScene("watcherqueen");
ShipSingleton.Instance.spawnShipID = ShipID;
}
继续出现此错误:
错误 CS0246 找不到类型或命名空间名称“Ship”(您是否缺少 using 指令或程序集引用?
我是否可能在按钮脚本中缺少对公共枚举的引用?
哦,我明白了现在的问题是什么(我也会在另一个问题中解决它)--
这条线需要参考ShipSingleton.Ship
而不是仅仅Ship
:
public Ship ShipID = ShipSingleton.Ship.BasicShip;
所以它应该看起来像这样:
public ShipSingleton.Ship ShipID = ShipSingleton.Ship.BasicShip;
这是因为枚举类型Ship
是的成员ShipSingleton
。如果Ship
在命名空间级别声明如下:
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)