Says .Length doesn't exist

Unity and Visual Studios says the music player doesn’t contain a defination for length.
I looked and I don’t have anything different for the code other than the name for the audio source.

1 Like

I forgot to place an s in FindObjectsOfType.

I Did the same mistake and i created a method thanks for sharing look what i did
it worked though


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

   public class musicplayer : MonoBehaviour {
   


 **private int Length;**

   

 private void Awake(){
        int nummusicplayers = FindObjectOfType<musicplayer>().Length;
        print("Num of musicplayers in this scene" + nummusicplayers);
       
        DontDestroyOnLoad(gameObject);
    }
 }

Just as a heads-up, code examples are best copy/pasted into your posts as opposed to screenshots, you can then apply the code formatting to add the syntax highlight. Doing so enables those that may offer to help you the ability to copy/paste a chunk of your code back to you with perhaps a suggestion or a correction without having to type out the whole thing. Screenshots are however really useful for error messages and details from the Unity editor itself.

Hope this helps :slight_smile:


1 Like

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

Privacy & Terms