- Home /
Problem with sendmessage to all types of GO
hello, tonight I've been working on a MP system. I kinda finished this, except from the tutorial I had to convert JS to C#. I'm pretty sure this I my last problem before it's finished.
// Notify our objects that the level and the network is ready
Transform[] go = FindObjectOfType(typeof(Transform));
int go_len = go.Length;
for (int i=0;i<go_len;i++)
{
go[i].SendMessage("OnNetworkLoadedLevel",
SendMessageOptions.DontRequireReceiver);
}
}
Worked in JS, but here I get a error on that 2nd line:
"Cannot implicity convert type 'UnityEngine.Object' to 'UnityEngine.Transform[]'"
Answer by Chronos-L · Jan 13, 2013 at 06:09 AM
You are using FindObjectOfType()
which "Returns the first active loaded object of Type type."--Object.FindObjectOfType, Unity Script Reference
You should use FindObjectsOfType()
instead. FindObjectOfType script reference
Just change line 2 to
Transform [] go = FindObjectsOfType(typeof(Transform)) as Transform[];
and you are good to go.
Side note, if the as Transform[]
is not put in, it will become an Object array ins$$anonymous$$d of a Transform array.