So i’m gonna have many characters of different types, and
they may share sounds they emit.
So dragging sounds to the inspector 1 by 1, for every character type in my scene is tedious.
Can you just access any sound in your Assets and play it from code?
So far what i got is giving me errors saying:
Cannot implicitly convert type UnityEngine.Object to UnityEngine.AudioCLip
using UnityEngine;
using System.Collections;
public class PlaySouuunn : MonoBehaviour {
AudioClip vv = Resources.Load("Blow");
void Start(){
audio.PlayOneShot(vv);
}
void Update(){
//do an if or whatever statement
}
}
This one also doesn’t work
AudioSource.PlayClipAtPoint(clip, transform.position);
So is this the line that has the problem?
—> AudioClip vv = Resources.Load(“Blow”);
I got this code from a example online, it was an answer here in UnityAnswers i think.
but they had it in javascript as:
function PlayFile(file: String){ // file name without extension
var clip: AudioClip = Resources.Load(file);
// example 1: play with PlayOneShot
audio.PlayOneShot(clip);
// example 2: play without an AudioSource component
AudioSource.PlayClipAtPoint(clip, transform.position);
// example 3: play with Play
audio.clip = clip;
audio.Play();
}
So you see i’m basically doing the same
Auddioclip vv = Resources.Load
and then the play.
And yes i have a Resources folder in my assets folder