- Home /
Question by
kittureddy425 · Apr 09, 2013 at 08:14 PM ·
c#randomaudioclip
how to solve in this error "The name `CowboyRap' does not exist in the current context" .using below script
using UnityEngine; using System.Collections;
public class Audio_RanGen : MonoBehaviour {
public AudioClip[] sound=new AudioClip[1]{CowboyRap};
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
void OnGUI()
{
if(GUI.Button(new Rect(100,200,200,50),"Random Number Genaration"))
{
for(int i=0;i<14;i++)
{
print ("hiiii");
print(sound.Length);
print(sound[0]);
audio.clip=sound[Random.Range(0,sound.Length)];
audio.Play();
}
}
}
}
Comment
Answer by Dracorat · Apr 09, 2013 at 08:29 PM
I'm assuming "CowboyRap" is the name of an audio clip file?
If so, try changing to:
public AudioClip[] sound=new AudioClip[1];
Then, in the inspector, drag the file to the "AudioClip" property that should show up.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to Activate Random GameObjects? (C#) 1 Answer
Spawn Random Enemy 3 Answers
instantiating vertically 2 Answers