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.
Inspector Parameters
- Use Button: The button used to use/unuse a touched object.
- Controller Events: The controller 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
On
prefix. e.g.MyEvent
->OnMyEvent
.
Class Methods
IsUseButtonPressed/0
public virtual bool IsUseButtonPressed()
- Parameters
- none
- Returns
bool
- Returns true if 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 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 virtual 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 virtual 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.
AttemptUse/0
public virtual void AttemptUse()
- Parameters
- none
- Returns
- none
The AttemptUse method will attempt to use the currently touched 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