Hey guys, I’m working on a game where the user has a selection of skills to use. I’ve got sounds playing on animation using animation event + the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SkillSound : MonoBehaviour {
public AudioClip soundClip;
public AudioSource audioS;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void Thump()
{
audioS.PlayOneShot(soundClip);
}
From there I’ve added an audio source to the character, drag the above script onto the character, and drag the source + sound clip onto the script.
What I’m looking to do is two things:
1) Have the script play a random sound (1 of 3 or 4 selections - think swinging sounds) on attack,
2) I’d like to be able to make it so that I can have a selection of sounds to play based on the skill I’m using (each has it’s own animation (or clone of animation) to help with the event triggering- skills are already set up) without having to create a new script for each one (and in turn having to have 40 scripts hanging off of one character prefabs). Arrays are ideal but I’m not the greatest with them.
Any help would be greatly appreciated!
Thank you