//每次回到unity就会报错,但是运行时没有异常,赋值都赋上去了,能正常游戏,不知为什么会报错
//NullReferenceException: Object reference not set to an instance of an object
//Reflecter ..ctor () (at Assets/Scripts/Towers/Reflecter .cs:7)
public class TowerAttr
{
public int Hp;
public string DesEff;
public TowerAttr(int hp,string deseff)
{
Hp = hp;
DesEff = deseff;
}
}
public class TowerAttrFactroy
{
public Dictionary<int, TowerAttr> TowerAttrDict = new Dictionary<int, TowerAttr>();
public TowerAttrFactroy()
{
TowerAttrDict.Add(0, new TowerAttr(300, "tyellow"));
TowerAttrDict.Add(1, new TowerAttr(400, "tred"));
TowerAttrDict.Add(2, new TowerAttr(350, "tgreen"));
TowerAttrDict.Add(3, new TowerAttr(300, "tblue"));
TowerAttrDict.Add(4, new TowerAttr(300, "tindigo"));
TowerAttrDict.Add(5, new TowerAttr(300, "tgreen"));
TowerAttrDict.Add(6, new TowerAttr(300, "tyellow"));
TowerAttrDict.Add(7, new TowerAttr(300, "tblue"));
TowerAttrDict.Add(8, new TowerAttr(300, "tpurple"));
TowerAttrDict.Add(9, new TowerAttr(1000, "tgrey"));
TowerAttrDict.Add(10, new TowerAttr(800, "tgrey"));
TowerAttrDict.Add(11, new TowerAttr(2000, "tgrey"));
TowerAttrDict.Add(12, new TowerAttr(200, "tblack"));
}
public TowerAttr GetTowerAttr(int id)
{
return TowerAttrDict[id];
}
}
public class TowerFather:MonoBehaviour
{
protected int Hp;
private int TotalHp;
protected string DesEffect;
private bool secondget = false;
private Slider BloodSlider;
public TowerFather(TowerAttr towerAttr)
{
Hp = towerAttr.Hp;
DesEffect = towerAttr.DesEff;
}
}
public class Reflecter : TowerFather
{
//报错位置 public Reflecter() : base(GameManager.Instance.factroyManager.TowerattrFactroy.GetTowerAttr(9))
{
Debug.Log(GameManager.Instance.factroyManager.TowerattrFactroy.GetTowerAttr(9).DesEff);
}
}
public class GameManager : MonoBehaviour {
#region 单例
private static GameManager _instance;
public static GameManager Instance
{
get
{
return _instance;
}
}
#endregion
public FactroyManager factroyManager;
public GameController gameController;
//信息
private void Awake()
{
_instance = this;
factroyManager = new FactroyManager();
gameController = GameObject.Find("bg").GetComponent<GameController>();
}
}