-1

Hello I'm developing a Virtual Reality App in Unity and I'm using Steam Virtual Reality, VRTK and HTC VIVE. Like in PC we Use "Void OnMouseDown" to detect clicks on a game object, how we can achieve this in Virtual Reality? Suppose We have Virtual Reality scene with a single Cube. Now what I want is to detect clicks on the objects so how can I achieve this in Virtual Reality? Help Me Please Thanks.

public void OnMouseDown()
{
   //some code    
}
killer_mech
  • 1,568
  • 13
  • 26
Nouman Khan
  • 3
  • 1
  • 6

1 Answers1

1

You should refer to this tutorial on VRTK. You can also refer the following example in your VRTK package.

VRTK/Examples/005_Controller/BasicObjectGrabbing

You have two parts for this:

  • You will need to add VRTK_InteractTouch & VRTK_InteractGrab scripts on your Left & Right Controllers. And setup grab button to your desired button. By default its set to Grip Press.
  • After you have setup controller its time to setup the object which you want to make interactable. Select your Cube. Go to Windows. Point to VRTK option. Click Setup Interactable Object. A popup will show up called Setup Object. You can go through the options and make desired changes else you can directly click on setup selected object button. It will add the desired scripts on your object. You can also add manually each of these scripts which are shown in the tutorial if you need to else use the options from windows directly to add intractability.

You also might want to go through this. If you need a grabbed object there is a specific function mentioned in document called GetGrabbedObect.


As a first time developer it will be bit confusing to use VRTK but trust me its one of the most powerful tool to make VR games. Secondly keep on checking the tutorial videos about using VRTK and go through the examples folder.

killer_mech
  • 1,568
  • 13
  • 26
  • ok sir i will test this actually i am new to VR and in PC i was using Void OnMouseDown i will test this and will tell you – Nouman Khan Dec 19 '18 at 07:19
  • in pc version when i click on the cube the cube starts to play it animation now same it is the same thing which i want in VR i will test your solution – Nouman Khan Dec 19 '18 at 07:22
  • There is no mousedown in HTC vive VR as we will be mostly using HTC controller. – killer_mech Dec 19 '18 at 07:22
  • Its in VRTK_interactable object under touch option as touch highlight color. – killer_mech Dec 19 '18 at 07:24
  • You can close the question by marking the solution as answer if this worked for you – killer_mech Dec 19 '18 at 07:25
  • yes first i will test it then tell u – Nouman Khan Dec 19 '18 at 07:26
  • how to use that GetGrabbedObect. function to play the animation of the cube let say i have a simple animation on cube so how to use that GetGrabbedObect. function in my other code – Nouman Khan Dec 19 '18 at 07:37
  • and what about VREasy asset is it good or better than VRTK? – Nouman Khan Dec 19 '18 at 07:49
  • you can refer to following answer to get the input from controller. https://stackoverflow.com/questions/41962705/detect-controller-input-in-vrtk – killer_mech Dec 19 '18 at 08:09
  • Although you can use the class events mentioned in VRTK_InteractGrab to setup the "GrabButtonPressed" and in that you can get the attached object from GetGrabbedObject(). Else you can constantly check for the grab state in update method like in above link – killer_mech Dec 19 '18 at 08:12
  • No, I have not user VREasy so I do not know. You can try and check. I had used VRTK two years ago and at the time only VRTK and NewtonVR was available. I found VRTK gave easy access to the things I needed so I preffered VRTK, also newton VR at the time lacked some basic features(i cant recollect specifically which ones though). – killer_mech Dec 19 '18 at 08:14
  • i am getting this error by following the link that you refer me Operator `!=' cannot be applied to operands of type `method group' and `null' – Nouman Khan Dec 19 '18 at 08:56