So I made a C# script for audio but some reason the audio is playing like 20 times and echos. I don’t think it’s a script problem but figured I would post it here to double check. Is it because the keydown is in my update? Any idea what may be wrong if it’s not the script?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Audio : MonoBehaviour
{
public AudioClip audioClip;
AudioSource audioSource;
void Start()
{
audioSource = GetComponent<AudioSource>();
}
void Update()
{
if (Input.GetKeyDown("k"))
{
AudioLeft();
}
}
public void AudioLeft()
{
if (audioClip) audioSource.PlayOneShot(audioClip, 0.5F);
}
}