I’m trying to figure out how to make a sound I have play on a certain frame rather than have it play instantaneously when I trigger the animation. What would be the most efficient way to do this (using c# preferably)?
Here’s the script that plays my animation:
using UnityEngine;
using System.Collections;
public class Boulder : MonoBehaviour {
public AudioClip RockRolling;
public AudioClip boom;
float time;
// Use this for initialization
void Start () {
gameObject.collider.enabled = true;
}
void OnTriggerEnter(Collider col) {
if(col.gameObject.tag == "Player") {
animation.Play("BoulderMove");
audio.PlayOneShot(boom);
gameObject.collider.enabled = false;
}
}
// Update is called once per frame
void Update () {
}
}