From ba26ec513ddcbd054e924517f73089e1d16395ba Mon Sep 17 00:00:00 2001 From: Robert Wetzold Date: Wed, 17 Aug 2016 12:47:54 +0200 Subject: [PATCH] fix(Controller): enhance AutoGrab script AutoGrab would fail if the controllers initially already touched something. This is now fixed. Also stronger typing has been introduced and the script flow fixed so that now error messages also appear in the console. --- .../Scripts/VRTK_ObjectAutoGrab.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_ObjectAutoGrab.cs b/Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_ObjectAutoGrab.cs index 7cd93fc78..95d136748 100644 --- a/Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_ObjectAutoGrab.cs +++ b/Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_ObjectAutoGrab.cs @@ -5,7 +5,7 @@ public class VRTK_ObjectAutoGrab : MonoBehaviour { - public GameObject objectToGrab; + public VRTK_InteractableObject objectToGrab; public bool cloneGrabbedObject; private VRTK_InteractGrab controller; @@ -13,15 +13,16 @@ public class VRTK_ObjectAutoGrab : MonoBehaviour private IEnumerator Start() { controller = GetComponent(); - if (!controller) { Debug.LogError("The VRTK_InteractGrab script is required to be attached to the controller along with this script."); + yield break; } - if (!objectToGrab || !objectToGrab.GetComponent()) + if (!objectToGrab) { - Debug.LogError("The objectToGrab Game Object must have the VRTK_InteractableObject script applied to it."); + Debug.LogError("You have to assign an object that should be grabbed."); + yield break; } while (controller.controllerAttachPoint == null) @@ -29,12 +30,13 @@ private IEnumerator Start() yield return true; } - var grabbableObject = objectToGrab; + VRTK_InteractableObject grabbableObject = objectToGrab; if (cloneGrabbedObject) { grabbableObject = Instantiate(objectToGrab); } - controller.GetComponent().ForceTouch(grabbableObject); + controller.GetComponent().ForceStopTouching(); + controller.GetComponent().ForceTouch(grabbableObject.gameObject); controller.AttemptGrab(); } }