- Home /
Can anyone convert this for loop (which is in Java) into c# i
hi, iam trying to do a unity tutorial but it's in java and i work with C# script so i tried to convert every code into c# the only thing i have a problem now is
for (var go : GameObject in FindObjectsOfType(GameObject))
{
go.SendMessage("OnNetworkLoadedLevel",
SendMessageOptions.DontRequireReceiver);
}
i tried to do this
foreach(GameObject GameobjectsInGame in FindObjectsOfType(GameObject))
{
GameobjectsInGame.SendMessage("OnNetWorkLoadedLevel",
SendMessageOptions.DontRequireReceiver);
}
but its not working and keep saying GameObject is not a Type type etc, but in the tutorial they used it like that :(, i tried a foreach loop instead of a for loop cause it seem more logical to me that forloops in java works in another way and as there is a "IN" i thougth c# version of that would be a foreach.
original tutorial from unity. http://download.unity3d.com/support/resources/files/MultiplayerTutorial.pdf
Answer by CHPedersen · Nov 17, 2011 at 12:21 PM
It's because in C#, you need to add "typeof" in front of it:
foreach (GameObject GameobjectsInGame in FindObjectsOfType(typeof(GameObject)))
{
GameobjectsInGame.SendMessage("OnNetWorkLoadedLevel",
SendMessageOptions.DontRequireReceiver);
}
Excellent. :) If the answer helped you, please mark it as accepted.
Your answer
Follow this Question
Related Questions
convert java script to c# 1 Answer
Can someone help me convert this camera controller to c# script 1 Answer
Convert this line of javascript to C# (easy) 1 Answer
Convert small C# Code to JavaScript 2 Answers
Multiple Cars not working 1 Answer