GetType() Reflection Issue

I didn’t have any luck with the GetType() reflection here - perhaps as I’d named my GameObject something different to the name of the class… So I used
if (FindObjectsOfType<MusicPlayer>().Length > 1)

instead, which worked.

Just FYI if anyone else has a problem with the music restarting…

You should probably keep your names as consistent as possible, so you don’t run into issues later on. Also GetType() was just a catchall for finding all Objects with the same type as MusicPlayer (or whatever your script class was. Your above method is just as valid, but I guess Rick wanted to show us another way. More ways you know, the better.

Privacy & Terms