I attached DrumPad a C # script to my Drummer, an empty. I added a few sound samples to Drummer.
I added a Drum1 button to my scene. When I play the scene the sound plays once, when I press the button I get the same sound instead a possible random sound.
PLEASE HELP me with my script.
I wrote the following code in Unity 5.o
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class DrumPad : MonoBehaviour {
public AudioClip clips;
// Use this for initialization
void Start () {
LetsPlay ();
}
void LetsPlay(){
int clipPick = Random.Range (0, clips.Length);
GetComponent<AudioSource>().clip = clips [clipPick];
GetComponent<AudioSource>().Play ();
}
}