- Home /
Portal Sound start AFTER the Teleportation
Hey Guys, i have another Problem. I have Portals (All in the same Scene) which are working perfektly, but the sound start AFTER the teleportation. I want to start it immediately with the ParticleSystem, but i cant find the solution. Can u help me? The Trigger is my HeadCollider of my VR Rig.
using System;
using System.Collections;
using UnityEngine;
public class PortalScript : MonoBehaviour
{
public ParticleSystem PortalSytem;
public GameObject Trigger;
public GameObject Player;
public GameObject Destination;
public int TimeInSeconds;
public float MinDistance;
private void Update()
{
float dist = Vector3.Distance(Trigger.transform.position, PortalSytem.gameObject.transform.position);
Debug.Log("Distance: " + dist);
if (dist < MinDistance)
{
Trigger.GetComponent<AudioSource>().Play();
PortalSytem.Play();
StartCoroutine("startteleport");
}
}
IEnumerator startteleport()
{
yield return new WaitForSeconds(TimeInSeconds);
PortalSytem.Stop();
Player.transform.position = Destination.transform.position;
}
}
Guess problem is not your code but your sound might be taking too long to start. Click your sound file on editor and see it yourself in the inspector. I posted a sample image below. What im trying to tell is the red line could be almost the same time with your TimeInSeconds
. So you may have to trim the sound a bit. Btw i suggest you to name your fields according to camelCase and your methods to PascalCase e.g. Trigger => trigger, startteleport() => StartTeleport()
Your answer
Follow this Question
Related Questions
How to make a sound play and have a delay after so it can't be activated again very fast? 1 Answer
How to WaitforSeconds a GuiButton ? 0 Answers
30 Objects all firing at exactly the same time and not randomly 1 Answer
How can I add a "delay" before switching back to realtime? (Read description for more detail, sorry) 1 Answer
Add Delay to Moving Platform 1 Answer