塔防单例 List<T>
GameManeger脚本:Mono
internal stastic GameManager instance;//设置静态变量
public List<EnemeyBase> enemyList;//泛型
public stastic GameManager Instance
{
get
{
if(instnce==null)
{
GameObject obj=new GameObject("GameManager");
instance=obj.AddComponent<GameManager>();
}
return instance;
}
}
public void AddEnemy(EnemeyBase enemy)
{
enemyList.Add(enemy);
}
public void RemoveEnemy(EnemyBase enemy)
{
enemyList.Remove(enemy);
}
public virtual void Start()
{
GameManager.Instance.AddEnemy(this);//添加到列表里面
}
private void Ondisable()
{
GameManager.Instance.removeEnemy(this);
}