x


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

more ▼

asked Nov 17 '11 at 12:14 PM

Conny14156 gravatar image

Conny14156
18 3 4 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);
    }
more ▼

answered Nov 17 '11 at 12:21 PM

CHPedersen gravatar image

CHPedersen
6k 13 22 61

Thanks! it works now

Nov 17 '11 at 01:23 PM Conny14156

Excellent. :) If the answer helped you, please mark it as accepted.

Nov 17 '11 at 01:26 PM CHPedersen
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4154
x295
x225

asked: Nov 17 '11 at 12:14 PM

Seen: 1320 times

Last Updated: Nov 17 '11 at 01:26 PM