Question by
wraith1821 · Oct 10, 2016 at 12:12 PM ·
c#collisionaudio
Audio Timing sync with Collision Object Appearance
I am creating a jump scare and when the collider is triggered the audio plays before the renderer displays the object(capsule). So just trying to figure out a way to sync the two so that the audio starts at the same time as the capsule appears. Thanks ahead of time. I know there's unnecessary code in there. I was moving stuff around to see if the it was runtime lag. Code below:
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class JumpScareCollider : MonoBehaviour {
public GameObject jumpScareObject;
public float destroyInSeconds;
public AudioClip jumpScareAudio;
void Start ()
{
GetComponent<AudioSource> ().playOnAwake = false;
GetComponent<AudioSource> ().clip = jumpScareAudio;
jumpScareObject.GetComponent<Renderer>().enabled = false;
}
public void update()
{
}
public void OnTriggerEnter(Collider col)
{
if (jumpScareObject != null)
StartCoroutine("Wait");
GetComponent<AudioSource> ().Play ();
}
private IEnumerator Wait ()
{
jumpScareObject.GetComponent<Renderer>().enabled = true;
yield return new WaitForSeconds (destroyInSeconds);
Destroy (jumpScareObject);
}
}
Comment
Your answer
Follow this Question
Related Questions
Invisible objects appear after collision 2 Answers
Can't get object to destroy itself on collision. 0 Answers
LevelChange On MouseClick 0 Answers
C# overriding past velocity 0 Answers
Best practive when removing pickup gameObject and its instances 0 Answers