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(); } }