Question by
unity_6N9jDN9nu-MAaQ · Oct 25, 2018 at 11:08 AM ·
scripting problemscripting beginner
How do i find out if teleport was unsuccessful? (VR VIVE)
I already found out that the VRTK_BasicTeleport_UnityEvents script tells me if the player teleported. But now I want to find out if the teleport was unsuccessful like when the player chose an invalid area because I want to add an error sound when this happens. I suck at scripting so I don't know if this is possible or if there is an easy solution. I added the VRTK script below.
using UnityEngine;
using UnityEngine.Events;
using System;
[AddComponentMenu("VRTK/Scripts/Utilities/Unity Events/VRTK_BasicTeleport_UnityEvents")]
public sealed class VRTK_BasicTeleport_UnityEvents : VRTK_UnityEvents<VRTK_BasicTeleport>
{
[Serializable]
public sealed class TeleportEvent : UnityEvent<object, DestinationMarkerEventArgs> { }
public TeleportEvent OnTeleporting = new TeleportEvent();
public TeleportEvent OnTeleported = new TeleportEvent();
protected override void AddListeners(VRTK_BasicTeleport component)
{
component.Teleporting += Teleporting;
component.Teleported += Teleported;
}
protected override void RemoveListeners(VRTK_BasicTeleport component)
{
component.Teleporting -= Teleporting;
component.Teleported -= Teleported;
}
private void Teleporting(object o, DestinationMarkerEventArgs e)
{
OnTeleporting.Invoke(o, e);
}
private void Teleported(object o, DestinationMarkerEventArgs e)
{
OnTeleported.Invoke(o, e);
}
}
Comment
Good day.
Why not storing the position right before try to teleport, and compare it with the position after teleport. If vector3.distance between the 2 positions is higger then a quantity, it means the teleport was successfull, or something like this.