{"__v":0,"_id":"58796782cd4a9c37007c9745","category":{"version":"58796781cd4a9c37007c96ef","project":"571fa55ca0acd42000af9545","_id":"58796781cd4a9c37007c96f4","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-01-01T16:45:52.489Z","from_sync":false,"order":6,"slug":"interactions","title":"Interactions"},"parentDoc":null,"project":"571fa55ca0acd42000af9545","user":"571fa519db52d01700f5cf3d","version":{"__v":4,"_id":"58796781cd4a9c37007c96ef","project":"571fa55ca0acd42000af9545","createdAt":"2017-01-13T23:49:21.393Z","releaseDate":"2017-01-13T23:49:21.393Z","categories":["58796781cd4a9c37007c96f0","58796781cd4a9c37007c96f1","58796781cd4a9c37007c96f2","58796781cd4a9c37007c96f3","58796781cd4a9c37007c96f4","58796781cd4a9c37007c96f5","58796781cd4a9c37007c96f6","58796781cd4a9c37007c96f7","58796781cd4a9c37007c96f8","58796781cd4a9c37007c96f9","58796781cd4a9c37007c96fa","58796781cd4a9c37007c96fb","58796781cd4a9c37007c96fc","58796781cd4a9c37007c96fd","58796781cd4a9c37007c96fe","58796781cd4a9c37007c96ff","58796781cd4a9c37007c9700","58b157ca1756cf370022f90d","58b1596f5dae732f00adeca2","58b1605a5dae732f00adecb1"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Mukota","version_clean":"3.1.0","version":"3.1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-01-01T16:47:28.789Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"## Overview\n\nThe Interact Use script is attached to a Controller object and requires the `VRTK_ControllerEvents` script to be attached as it uses this for listening to the controller button events for using and stop using interactable game objects.\n\nIt listens for the `AliasUseOn` and `AliasUseOff` events to determine when an object should be used and should stop using.\n\nThe Controller object also requires the `VRTK_InteractTouch` script to be attached to it as this is used to determine when an interactable object is being touched. Only valid touched objects can be used.\n\nAn object can be used if the Controller touches a game object which contains the `VRTK_InteractableObject` script and has the flag `isUsable` set to `true`.\n\nIf a valid interactable object is usable then pressing the set `Use` button on the Controller (default is `Trigger`) will call the `StartUsing` method on the touched interactable object.\n\n## Class Events\n\n * `ControllerUseInteractableObject` - Emitted when a valid object starts being used.\n * `ControllerUnuseInteractableObject` - Emitted when a valid object stops being used.\n\n## Unity Events\n\nAdding the `VRTK_InteractUse_UnityEvents` component to `VRTK_InteractUse` object allows access to `UnityEvents` that will react identically to the Class Events.\n\n * `OnControllerUseInteractableObject` - Emits the ControllerUseInteractableObject class event.\n * `OnControllerUnuseInteractableObject` - Emits the ControllerUnuseInteractableObject class event.\n\n## Event Payload\n\n * `uint controllerIndex` - The index of the controller doing the interaction.\n * `GameObject target` - The GameObject of the interactable object that is being interacted with by the controller.\n\n## Class Methods\n\n### GetUsingObject/0\n\n  > `public GameObject GetUsingObject()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `GameObject` - The game object of what is currently being used by this controller.\n\nThe GetUsingObject method returns the current object being used by the controller.\n\n### ForceStopUsing/0\n\n  > `public void ForceStopUsing()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * _none_\n\nThe ForceStopUsing method will force the controller to stop using the currently touched object and will also stop the object's using action.\n\n### ForceResetUsing/0\n\n  > `public void ForceResetUsing()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * _none_\n\nThe ForceResetUsing will force the controller to stop using the currently touched object but the object will continue with it's existing using action.\n\n## Example\n\n`VRTK/Examples/006_Controller_UsingADoor` simulates using a door object to open and close it. It also has a cube on the floor that can be grabbed to show how interactable objects can be usable or grabbable.\n\n`VRTK/Examples/008_Controller_UsingAGrabbedObject` shows that objects can be grabbed with one button and used with another (e.g. firing a gun).","excerpt":"","slug":"vrtk_interactuse","type":"basic","title":"VRTK_InteractUse"}
## Overview The Interact Use script is attached to a Controller object and requires the `VRTK_ControllerEvents` script to be attached as it uses this for listening to the controller button events for using and stop using interactable game objects. It listens for the `AliasUseOn` and `AliasUseOff` events to determine when an object should be used and should stop using. The Controller object also requires the `VRTK_InteractTouch` script to be attached to it as this is used to determine when an interactable object is being touched. Only valid touched objects can be used. An object can be used if the Controller touches a game object which contains the `VRTK_InteractableObject` script and has the flag `isUsable` set to `true`. If a valid interactable object is usable then pressing the set `Use` button on the Controller (default is `Trigger`) will call the `StartUsing` method on the touched interactable object. ## Class Events * `ControllerUseInteractableObject` - Emitted when a valid object starts being used. * `ControllerUnuseInteractableObject` - Emitted when a valid object stops being used. ## Unity Events Adding the `VRTK_InteractUse_UnityEvents` component to `VRTK_InteractUse` object allows access to `UnityEvents` that will react identically to the Class Events. * `OnControllerUseInteractableObject` - Emits the ControllerUseInteractableObject class event. * `OnControllerUnuseInteractableObject` - Emits the ControllerUnuseInteractableObject class event. ## Event Payload * `uint controllerIndex` - The index of the controller doing the interaction. * `GameObject target` - The GameObject of the interactable object that is being interacted with by the controller. ## Class Methods ### GetUsingObject/0 > `public GameObject GetUsingObject()` * Parameters * _none_ * Returns * `GameObject` - The game object of what is currently being used by this controller. The GetUsingObject method returns the current object being used by the controller. ### ForceStopUsing/0 > `public void ForceStopUsing()` * Parameters * _none_ * Returns * _none_ The ForceStopUsing method will force the controller to stop using the currently touched object and will also stop the object's using action. ### ForceResetUsing/0 > `public void ForceResetUsing()` * Parameters * _none_ * Returns * _none_ The ForceResetUsing will force the controller to stop using the currently touched object but the object will continue with it's existing using action. ## Example `VRTK/Examples/006_Controller_UsingADoor` simulates using a door object to open and close it. It also has a cube on the floor that can be grabbed to show how interactable objects can be usable or grabbable. `VRTK/Examples/008_Controller_UsingAGrabbedObject` shows that objects can be grabbed with one button and used with another (e.g. firing a gun).