我陷入了相当愚蠢的境地:我正在制作泛型类的新实例,但它返回“怪异”的null .
Rule rule2 = new Rule(); // initiate the class
Debug.Log(rule2); //1st debug
rule2.RuleSetup(r: "CaughtEnough", li: 0); //setting up the parameters
Debug.Log(rule2.rule); //2nd debug
第一次调试给了我
null
UnityEngine.Debug:Log(Object)
同时设置参数工作,第二次调试给我
CaughtEnough
UnityEngine.Debug:Log(Object)
这应该是在适当的类实例中 .
它给我带来的一个(只是到目前为止)的问题是,如果我在这个规则类实例中调用
Invoke(rule, 0f);
它给了我NullReferenceException错误 . 但同时实际功能
CaughtEnough();
工作正常,如预期的那样 .
任何想法可能是问题的根源以及如何克服它?
UPD还会按照要求发布Rule类的设置部分,尽管它很简单
public class Rule : MonoBehaviour {
public string rule;
public int leftInt;
public Dictionary leftDict;
public float countdown;
public int outcome;
public CatchManager catchMan;
public Net net;
// Use this for initialization
void Start () {
RuleSetup();
}
public void RuleSetup(string r = "NoRule", int li = 0, Dictionary ld = null, float cd = float.PositiveInfinity) {
rule = r;
leftInt = li;
leftDict = ld;
countdown = cd;
}
.....