- Home /
Question by
Lost_Syndicate · Jan 23, 2018 at 12:18 AM ·
javascriptaudiotrigger
Triggering audio in javascript
I need to know how to play a audioclip/audiosource in javascript. pleeeeasseee plepleplpalepallplwpelpelplse i need to know how. Ive been searching but all them come with errors.
Comment
Best Answer
Answer by Ginxx009 · Jan 23, 2018 at 01:31 AM
Hmm did you try something like this
CSharp
using UnityEngine; using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class ExampleClass : MonoBehaviour
{
void Start()
{
AudioSource audio = GetComponent<AudioSource>();
audio.Play();
audio.Play(44100); //Delay in number of samples, assuming a 44100Hz sample rate (meaning that Play(44100) will delay the playing by exactly 1 sec).
}
}
Javascript
#pragma strict
@RequireComponent(AudioSource)
function Start() {
var audio: AudioSource = GetComponent.<AudioSource>();
audio.Play();
audio.Play(44100);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612151109im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Audio Script 1 Answer
Changing current audio on trigger. 1 Answer
Scale messing with code 0 Answers
Problem with playing sound on Trigger-Enter 2 Answers
trigger audio and text from array 0 Answers