Hi.
I have an elevator platform which rises and lowers when the player enters or leaves the collider. I can get the sound to play but it willobly play when the movement has completed.
How can I make the sound play as the elevator moves?
Would I need to use a separate thread?
@ Chr15_v101Hi!
One way would be to start playing the sound OnCollisionStay if is not already playing, and stop playing when the player leaves the elevator OnCollisionExit
using UnityEngine;
using System.Collections;
public class ElevatorSoundScript : MonoBehaviour {
AudioSource elevatorAudioSource ;
void OnCollisionStay ( Collision collisionStayInfo ) {
if( collisionStayInfo.gameObject.tag == "Player" ) {
if(elevatorAudioSource.isPlaying == false){
elevatorAudioSource.Play();
}
}
}
void OnCollisionExit ( Collision collisionExitInfo ) {
if( collisionExitInfo.gameObject.tag == "Player" ) {
if(elevatorAudioSource.isPlaying == true){
elevatorAudioSource.Stop(); // may be better to fade out the sound before stopping
}
}
}
}
Hope it Helps , Regards