- Home /
convert type UnityEngine.Object to UnityEngine.AudioClip
Hi guys! I'm trying to make a OpenFilePanel like this one but I want to open a ogg file. I'm also writing in C#.
I have this:
AudioClip audio = Selection.activeObject;
if(audio == null){
EditorUtility.DisplayDialog("Select a music", "You must select a music first!", "Ok");
return;
}
string path = EditorUtility.OpenFilePanel("Teste", "", "ogg");
if(path.Length != 0){
WWW www = new WWW("file:///" + path);
}
I'm having this error: error CS0266: Cannot implicitly convert type 'UnityEngine.Object' to 'UnityEngine.AudioClip'. An explicit conversion exists (are you missing a cast?)
I tried somethings but got nothing. How can I make it? Thank you :)
Answer by Eric5h5 · May 03, 2013 at 09:09 PM
As the error says, you forgot to cast:
AudioClip audio = Selection.activeObject as AudioClip;
Likewise, this should also work:
AudioClip audio = (AudioClip)Selection.activeObject;
Your answer
Follow this Question
Related Questions
Cannot implicitly convert type `UnityEngine.Object' to `UnityEngine.GameObject' 1 Answer
instantiate object 1 Answer
Error after converting Jscript to C# 1 Answer
Error In C# 1 Answer
Cannot cast from source type to destination type ERROR! 2 Answers