The type or namespace name 'MusicPlayer' could not be found

Getting an error when I try to FindObjectsOfType. Any idea why?

“The type or namespace name ‘MusicPlayer’ could not be found”

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DoNotDestroy : MonoBehaviour

    void Awake()
      int numMusicPlayers = FindObjectsOfType<MusicPlayer>().Length;


MusicPlayer game object is in the scene.



It isn’t the name of the GameObject that matters in this case, it’s the name of the type which you are trying to find. You are specifying MusicPlayer but this can’t be found, this would suggest your class is called something else.

Ah got it - thanks!

1 Like

You’re very welcome Chris :slight_smile:

See also;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms