Audio won't play, no matter what code or method I try
Heya, What I'm trying to accomplish, is to have a short audio play whenever the player presses a button, which has been assigned to the X button on an XBOX ONE controller, under the name "Distraction" but for the life of me, I can't get it working.
Below is the script I've written:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DecoyScript : MonoBehaviour
{
public AudioSource AudioSource;
// Update is called once per frame
void Update()
{
}
void Distraction()
{
if (Input.GetButton("Distract"))
{
AudioSource.Play;
Debug.Log("Player used Distraction");
}
}
}
I have tried:
audio.Play(); AudioClip.Play(); AudioSource.Play(); AudioSource.enabled = true; AudioClip.enabled = true;
Among other terms from several tutorials and forums I've read, but no matter what I try, I cannot get the audio to play when I press the "Distract" button. I have also tried changing the input, but I'm just plain old stuck on this issue.
Any ideas on what could be preventing this from working?
Your answer
![](https://koobas.hobune.stream/wayback/20220612223159im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to reduce delay when playing sound 0 Answers
Pick Up Sound 0 Answers
Why won't my second Audio Source play? 0 Answers
Audio Clip Error. 2 Answers
Audio not playing in game 1 Answer