Hi there,
I have a Sound Trigger set up so that when the player enters the audio will play once. What I cant figure out is how to make a canvas I have with buttons appear AFTER the audio finishes. The canvas has buttons that when selected will trigger more audio and I do not want the user to press the button until the triggered audio completes. Below is the code I have so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioTrigger : MonoBehaviour
{
public AudioClip audclip;
public bool havePlayed = false;
void Start()
{
havePlayed = false;
GetComponent<AudioSource>().playOnAwake = false;
GetComponent<AudioSource>().clip = audclip;
}
void OnTriggerEnter(Collider whoCollidedWithMe) //Plays Sound whenever collision detected
{
if (!havePlayed) // !havePlayed is the same as havePlayed==false
{
// we haven't played yet, but someone collided with us. Who is it ?
if (whoCollidedWithMe.gameObject.tag == "Player")
{
GetComponent<AudioSource>().PlayOneShot(audclip);
Debug.LogWarning("are u working");
havePlayed = true; // we played, so never again
}
else
{
// not the player, so do nothing
}
}
}
}