Forum Discussion
enzedda
11 years agoExplorer
Using the mouse buttons
Greetings to you all. My first post.
I have my dk2 and i have free Unity.
I have setup mydk2 and it is great.
I have placed the Oculus Unity4 integration into a simple new Unity scene and all views/navigation works on the DK2 as it should.
I can easily import my Max objects/animations into Unity.
My Unity scene consists of a couple of spheres that when clicked on with the mouse cause other functions to operate on other included game objects. Very simple stuff as I have never used a game engine before and never scripted before.
But..as soon as I add the Unity4 integration into the scene I cannot use the mouse to "click" on anything?
The Rift display does not seem to allow any usage of the mouse buttons within the Unity scene
Is this normal?
I saw that the "c" key gives one a mouse cursor in the rift display but I cannot fathom how to utilise this.
Is there something I should have disabled or changed?
As I said before, I have never scripted before but I use 3dsMax and can generally understand most 3d terms.
Is there something I should have read about this problem and where might I look for enlightenment?
I have my dk2 and i have free Unity.
I have setup mydk2 and it is great.
I have placed the Oculus Unity4 integration into a simple new Unity scene and all views/navigation works on the DK2 as it should.
I can easily import my Max objects/animations into Unity.
My Unity scene consists of a couple of spheres that when clicked on with the mouse cause other functions to operate on other included game objects. Very simple stuff as I have never used a game engine before and never scripted before.
But..as soon as I add the Unity4 integration into the scene I cannot use the mouse to "click" on anything?
The Rift display does not seem to allow any usage of the mouse buttons within the Unity scene
Is this normal?
I saw that the "c" key gives one a mouse cursor in the rift display but I cannot fathom how to utilise this.
Is there something I should have disabled or changed?
As I said before, I have never scripted before but I use 3dsMax and can generally understand most 3d terms.
Is there something I should have read about this problem and where might I look for enlightenment?
16 Replies
Replies have been turned off for this discussion
- virrorExplorerHere are some code for you to try and learn from:
if(Input.GetKeyDown(KeyCode.Mouse0)) //Mouse button 0 is pressed
{
if((Time.realtimeSinceStartup - delayTime) > delayTimer) //Make sure player cant press to often
{
if(Camera.main != null) //Make sure you have a camera
{
Vector3 screenMiddle = new Vector3(Screen.width / 2, Screen.height / 2, 0); //Set raycast position to center of the screen
Ray ray = Camera.main.ScreenPointToRay(screenMiddle); //Create the ray vector
RaycastHit hit; //Variable for storing what the raycast hit
if (Physics.Raycast(ray, out hit, 2.0f)) //Do the raycast, fire the ray 2meters
{
GameObject hitGameObject = hit.collider.gameObject; //Grap the gameobject that was hit
switch (hitGameObject.name) //What object was hit?
{
case "Cube": //Object hit was a cube
{
//Do cool stuff here
break;
}
default: //The rest of the objects, do nothing here
{
break;
}
}
delayTime = 1;//Set delay time between clicks to 1sek
}
}
}
} - weasel47Heroic ExplorerTo add to what virror said, if you want a lot of different kinds of objects to respond to clicks in different ways, you can use messages to replicate the "OnMouseDown" functionality. You can make up your own function such as "OnVRClick," add a different version of it to each object that needs to respond to clicks, and then call it from virror's code like this:
hitGameObject.SendMessage("OnVRClick");
You can replace the entire "switch" codeblock with that. Each object can then decide for itself how to respond to the click. - enzeddaExplorerThanks Virror and Weasel47..
I wish you guys lived nextdoor !!
I'm gradually working my way thru the text book and believe it or not your code/s are making sense!
Not that I've gotten as far as placing them anywhere..well not yet anyhow.
There seems to be a lot of freedom available to manipulate game objects from the components. I never realised the many variations that one has access to.
My main aim at the start was to have a method from within Unity to move/scale and rotate my imported Max objects on any desired axis.
I would like a small clickable "menu" that I could use to do the transform on the "active" object by clicking the mouse on that menu.
Now I can do that with the Unity program but as soon as the Unity integration is applied I lost the mouse function.
So then you kind folk informed me about Raycasting and then..well here I am !
I must admit to using "Visual Actions" to achieve my goal. It was very very easy to do it that way but I cannot see in Visual Actions any way to set up or detect a Raycast from..I guess..the camera??
Just to EDIT. Whilst my result with Visual Actions worked great in just Unity..it then also removed any mouse functions once the Rift was attached..( with the Unity Integration package). But you already know of that.
Also after seeing you guys and your coding/scripting skills...well you've made me jealous ! So I do want to keep up with learning how to script "properly".
Any hints and scripts will be greatly appreciated if not immediately used or understood. I do thank you indeed. - weasel47Heroic ExplorerIf you're using the new GUI system for your menu (included in Unity 4.6 and the Unity 5 beta) you should look here for information and a script that will let you use your face as the mouse cursor in the GUI and "click" on whatever is centered in your view:
viewtopic.php?f=37&t=16710&hilit=gui
The new GUI system is great for things like menus. In the Rift, you'd want GUI canvases to be located in "world space" so they have a position within 3D space. - enzeddaExplorerThanks for that, weasel47,
You guys/gals are very interesting folk to be with.
I just wish that I knew more.
Luckily I knew BASIC enough (years ago) so that this C# so far isn't too nasty for me to study.
Interesting how it's quite similar
The method described, "look based" seems very useful!
I don't have the .6 version of Unity. I am using 4.5.5. The free version, I'm afraid.
I guess I should load in the 4.6 version but I'll keep 4.5.5 until I'm confident that anything I have learned can be easily reproduced by me. That's because of the luck I have with updating stuff !
I do find Unity very inspiring and being my first foray into what are known as "Games Engines" I am finding them extremely interesting indeed.
Now if it wasn't for that darned Rift and the loss of mouse clicking functions :) - virrorExplorerYou should go for 4.6.1 version, there have been pretty small changes to it other than the new GUI system (thats super amazing) so you should have a breeze upgrading.
As weasel47 said, sending messages is of course a lot more clean than a huge switch case, but also slightly more demanding. Should not matter in this case though since its used pretty seldom : )
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago