VRTK_InteractUse
Overview
Determines if the Interact Touch can initiate a use interaction with the touched Interactable Object.
Required Components:
VRTK_InteractTouch- The touch component to determine when a valid touch has taken place to denote a use interaction can occur. This must be applied on the same GameObject as this script if one is not provided via theInteract Touchparameter.
Optional Components:
VRTK_ControllerEvents- The events component to listen for the button presses on. This must be applied on the same GameObject as this script if one is not provided via theController Eventsparameter.VRTK_InteractGrab- The grab component to determine when a valid grab has taken place. This must be applied on the same GameObject as this script if one is not provided via theInteract Grabparameter.
Script Usage:
- Place the
VRTK_InteractUsescript on either:- The GameObject with the Interact Touch and Controller Events scripts.
- Any other scene GameObject and provide a valid
VRTK_ControllerEventscomponent to theController Eventsparameter and a validVRTK_InteractTouchcomponent to theInteract Touchparameter of this script.
Inspector Parameters
- Use Button: The button used to use/unuse a touched Interactable Object.
- Controller Events: The Controller Events to listen for the events on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.
- Interact Touch: The Interact Touch to listen for touches on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.
- Interact Grab: The Interact Grab to listen for grab actions on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.
Class Events
UseButtonPressed- Emitted when the use toggle alias button is pressed.UseButtonReleased- Emitted when the use toggle alias button is released.ControllerStartUseInteractableObject- Emitted when a use of a valid object is started.ControllerUseInteractableObject- Emitted when a valid object starts being used.ControllerStartUnuseInteractableObject- Emitted when a unuse of a valid object is started.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.
- All C# delegate events are mapped to a Unity Event with the
Onprefix. e.g.MyEvent->OnMyEvent.
Class Methods
IsUseButtonPressed/0
public virtual bool IsUseButtonPressed()
- Parameters
- none
- Returns
bool- Returnstrueif the use alias button is being held down.
The IsUsebuttonPressed method determines whether the current use alias button is being pressed down.
GetUsingObject/0
public virtual GameObject GetUsingObject()
- Parameters
- none
- Returns
GameObject- The GameObject of what is currently being used by this Interact Use.
The GetUsingObject method returns the current GameObject being used by the Interact Use.
ForceStopUsing/0
public virtual void ForceStopUsing()
- Parameters
- none
- Returns
- none
The ForceStopUsing method will force the Interact Use to stop using the currently touched Interactable Object and will also stop the Interactable Object's using action.
ForceResetUsing/0
public virtual void ForceResetUsing()
- Parameters
- none
- Returns
- none
The ForceResetUsing will force the Interact Use to stop using the currently touched Interactable Object but the Interactable Object will continue with it's existing using action.
AttemptUse/0
public virtual void AttemptUse()
- Parameters
- none
- Returns
- none
The AttemptUse method will attempt to use the currently touched Interactable Object without needing to press the use button on the controller.
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).
Updated less than a minute ago
