i was looking for a way to reproduce the sound inside a trigger…
var elevator_object : Transform;
var player1 : Transform;
var elevator_snd : AudioClip;
var speed_value = 0.4;
var go_up = false;
function Update(){
if (go_up){
elevator_object.transform.Translate(Vector3.up * Time.deltaTime * speed_value);
player1.transform.Translate(Vector3.up * Time.deltaTime * speed_value);}}
function OnTriggerStay(other : Collider){
if (Input.GetButtonDown("Jump")){
"the line here summons the audio file"
go_up = true;}}
I have above the type AudioClip, but i believe AudioSource has the member “play”… but how is the code to integrate it?..
thank you.
Place an AudioSource component (Component > Audio > Audio Source) on the elevator and drag an audio clip to it in the inspector. You don’t really need to specify the audio clip in code if there’s only one sound that you want to play. When the collider is triggered you can use:
gameObject.audio.Play();
thank you ! going to try …
I haven’t tested the code, but you should look up the script reference for these hints:
this way you can attach any audio source and audio clip you wanted:
reference:
var elevator_object : Transform;
var player1 : Transform;
var elevator_snd : AudioSource;
var clip : AudioClip;
var speed_value = 0.4;
var go_up = false;
function Update(){
if (go_up){
elevator_object.transform.Translate(Vector3.up * Time.deltaTime * speed_value);
player1.transform.Translate(Vector3.up * Time.deltaTime * speed_value);}}
function OnTriggerStay(other : Collider){
if (Input.GetButtonDown("Jump")){
elevator_snd.clip = clip;
elevator_snd.PlayOneShot(elevator_snd.clip);
go_up = true;}}