I have this piece of code here which is a part of an administrative console i am making.
I tried to give the user a bit more freedom as to what type the BroadcastMessage Parameters are.
consoleInterpretation=consoleText.Split("."[0]);
if(consoleInterpretation[0]=="Find"){
if(consoleInterpretation.length==4){
var typeSplit2:String[];
typeSplit2=consoleInterpretation[3].Split(":"[0]);
if(typeSplit2.length==2){
if(typeSplit2[1]=="int")
GameObject.Find(consoleInterpretation[2]).BroadcastMessage(consoleInterpretation[2],int.Parse(typeSplit2[0]));
if(typeSplit2[1]=="float")
GameObject.Find(consoleInterpretation[2]).BroadcastMessage(consoleInterpretation[2],float.Parse(typeSplit2[0]));
if(typeSplit2[1]=="String")
GameObject.Find(consoleInterpretation[2]).BroadcastMessage(consoleInterpretation[2],typeSplit2[0]);
if(typeSplit2[1]=="GameObject")
GameObject.Find(consoleInterpretation[2]).BroadcastMessage(consoleInterpretation[2],GameObject.Find(typeSplit2[0]));
else
GameObject.Find(consoleInterpretation[2]).BroadcastMessage(consoleInterpretation[2],typeSplit2[0]);
}
else
GameObject.Find(consoleInterpretation[2]).BroadcastMessage(consoleInterpretation[2],consoleInterpretation[3]);
}
else
GameObject.Find(consoleInterpretation[1]).BroadcastMessage(consoleInterpretation[2]);
}
When i type "Find.MyGameObject.AddPoints.8:int"
i get the following error
NullReferenceException
UnityEngine.GameObject.BroadcastMessage (System.String methodName, System.Object parameter) (at C:/BuildAgent/work/842f9557127e852/Runtime/ExportGenerated/Editor/UnityEngineGameObject.cs:287)
A Debug.Log line i added showed me that typeSplit2[0]=“8” and typeSplit2[1]=“int”
Any ideas as to what might be the problem?
EDIT:
Now even if i type Find.MyGameObject.SampleFunction.text
Where: SampleFunction(test:String)
It gives a null reference exception