HTC Vive Game Toggle Weapon function Ideas and demo (unity,c#)

Source: Internet
Author: User

</pre> the soul of a VR game or display program is real and immersive, and if a lot of UI is added to the scene, it will destroy the sense of reality and affect the feeling, so I think the UI should be converted into real objects in VR, such as display, button, etc. The interaction is increased, and the functionality of the UI is also realized by increasing the realism. <span style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 ">   above is nonsense, meaning UI best made 3d, personal feeling ... &LT;BR style= "Word-wrap:break-word"/></span></span></span><p><span style= " Font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "&GT;&NBSP;&NBSP;HTC Vive on Steam has a game called hoverjunkers, personal feeling is at present all HTC Vivefps Game top Works, the immersion is very strong, Although it is fiction of the end-of-the-line style of sci-fi, the gun feel to do is also very feeling, feeling the game of the function of the gun to do a good hand, so with their own thinking imitation of doing a bit, the general realization of work, the interface is humble, the code is too tender, there are many places to optimize, so Not only can exchange money, but also can be used as other functions, as a way, we have a better experience of this kind of interaction hope also share. </span></span></spaN></p><p><span style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "><span style=" Color:rgb (105,105,105); line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; Font-size:16px "><strong>: My Weibo"  </strong></span><span style= "Color:rgb ( 105,105,105); line-height:25px; font-size:32px; Word-wrap:break-word; font-family: ' Microsoft Yahei ' "><strong><span style=" Word-wrap:break-word "><span style=" color: Red Word-wrap:break-word "> Director of </span></span></strong></span><span Foundry Factory style=" Color:rgb (105,105,105); line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; Font-size:16px "><strong> ", want a big V fan not enough ah, everybody mutual powder Bai </strong></span></span></span ></span></p><p>&ltSpan style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "><span style=" Color:rgb (105,105,105); line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; font-size:16px "><strong></strong></span></span></span></span></ P><p><span style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "><span style=" Color:rgb (105,105,105); line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; font-size:16px "><strong></strong></span></span></span></span> </p><p><span style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "><span style=" Color:rgb (105,105,105); line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; font-size:16px "><strong><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; Line-height:25px "> This is Hoverjunkers's reload function, press and hold the menu key on the handle (that is, the button on the disc above), will pop up a 3d UI, the handle points to the selected weapon Release menu key will be selected weapon (selected weapon highlight) </span><br style= "Word-wrap:break-word; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "/><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; Font-size:16px; Line-height:25px "> Now through my thinking simple implementation of the above features </span></strong></span></span></span> </span></p><p><span style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "><span style=" Color:rgb (105,105,105); line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; font-size:16px "><strong><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "></span></strong></span></span></span></ Span></p><p><span style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span styLe= "FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "><span style=" Color:rgb (105,105,105); line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; font-size:16px "><strong><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "></span></strong></span></span></span></ Span></p><p><span style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "><span style=" Color:rgb (105,105,105); line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; font-size:16px "><strong><span style=" word-wrap:bReak-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "></span></strong></span></span></span></ Span></p><p><span style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "><span style=" Color:rgb (105,105,105); line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; font-size:16px "><strong><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "></span></strong></span></spAn></span></span></p><p><span style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "><span style=" Color:rgb (105,105,105); Font-weight:bold; line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; font-size:16px "><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; Line-height:25px "> This is the effect of making demo </span><br style=" Word-wrap:break-word; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "/><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; Font-size:16px line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "> principle is to tie the weapon and handle in advance, decorate 3d weapon list, what effect to look at the art (adjust the lattice appearance, normal material and highlight material work), from the handle to launch a Ray,ray collision weapon table lattice , the corresponding lattice activates the corresponding weapon, and the other cancels the activation. </span></span><br style= "Word-wrap:break-word; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "/><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "> said here seems to have done a very low thing, after all, the effect is realized, the novice is so easy to meet, as notes, hahaha haha </span></span><br style = "Word-wrap:break-word; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "/><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "> main code stickers: </span></span><bR style= "Word-wrap:break-word; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "/><span style=" FONT-SIZE:24PX; Word-wrap:break-word; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; line-height:25px "><span style=" Word-wrap:break-word; font-weight:700 "> I am a novice, I will work hard to learn code optimization code, so we first make a look at </span></span></span></span></span ></span></span></p><p><span style= "font-family: blackbody; Word-wrap:break-word; Color:rgb (105,105,105); font-size:16px; line-height:25px "><span style=" FONT-SIZE:24PX; Word-wrap:break-word "><span style=" Word-wrap:break-word; font-weight:700 "><span style=" Color:rgb (105,105,105); Font-weight:bold; line-height:25px; Word-wrap:break-word; font-family: ' Microsoft Yahei '; font-size:16px "><span style=" Word-wrap:break-word; font-weight:700; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25px "><span style=" Font-size:24px; Word-wrap:break-word; Color:rgb (105,105,105); font-family: ' Microsoft Yahei '; line-height:25px "><span style=" Word-wrap:break-word; font-weight:700 "></span></span></span></span></span></span></span ></p><pre name= "code" class= "CSharp" >using unityengine;using System.Collections;     public class Chooseweapon:monobehaviour {//handle steamvr_trackedobject TRACKDEOBJEC;    Weapon list public gameobject Weaponmenu;    Gun options in the Weapon list public gameobject Weaponmenugun;    Knife options in the weapon list public gameobject Weaponmeunknife;    Weapon on hand: knife public gameobject kinfe;    Weapons on hand: Gun public gameobject gun;    Emit a ray from the handle to select the weapon//ray starting position public Transform Raystart;    Ray direction public Transform Raytarget;    List start color menunormalcolor;    List highlight colors color Menuhighlightcolor;        void Awake () {//Get this component on the handle TRACKDEOBJEC = Getcomponent<steamvr_trackedobject> (); The knife deactivates the KINFE. SetActive (FALSE);     Weapon List Deactivation weaponmenu.setactive (false); }//Use this for initialization void Start () {//Get weapon list option initial color Material orignmaterial = Weaponmenugu        N.getcomponent<renderer> (). Material;        Menunormalcolor = Orignmaterial.color;    Make the highlight color Menuhighlightcolor = Menunormalcolor + Color.grey;        }//update is called once per frame void update () {} void Fixedupdate () {//Get VIVE handle input        var device = steamvr_controller.input ((int) trackdeobjec.index);        Real-time acquisition of laser starting point Vector3 Raystartpos = raystart.position;        Real-time acquisition of laser direction Vector3 raydirdctionn = raytarget.position;        Laser direction Vector3 rayfindirection = (raydirdctionn-raystartpos). normalized;        Emission ray Ray Ray = new Ray (Raystartpos, rayfindirection);        Raycasthit hitinfo = new Raycasthit ();             Print Ray Debug.drawray (Ray.origin, ray.direction *, Color.green); if (device. Gettouch (SteaMVR_Controller.ButtonMask.ApplicationMenu)) {//Press the menu key to activate the weapon list weaponmenu.setactive (true); If the laser touches the object (list) if (Physics.raycast (ray, out Hitinfo)) {if (Hitinfo.collider! = null) {//Ray selects the weapon list which option of the lattice, which will be highlighted, the ray left to cancel the highlight restore color; if (HitInfo.collider.gameObject.tag = = "Gun") {weaponmenugun.getcomponent<renderer> (). Material.color = Menuhig                    Hlightcolor; } else {weaponmenugun.getcomponent<renderer> (). Materia                    L.color = Menunormalcolor; } if (HitInfo.collider.gameObject.tag = = "Knife") {Weaponmeu                    Nknife.getcomponent<renderer> (). Material.color = Menuhighlightcolor; } else {Weaponmeunknife.getcomponenT<renderer> (). Material.color = Menunormalcolor;  }}}//If the menu button is released at the gun, it activates the gun, deactivates the knife and the menu if (Device. Gettouchup (SteamVR_Controller.ButtonMask.ApplicationMenu)) {//If the laser touches the object (list) if ( Physics.raycast (Ray, out Hitinfo)) {//Here I set the gun option's check tag to gun, and the knife option's grid tag is set to knife if (hitinfo.coll                                        Ider.gameObject.tag = = "Gun") {Debug.Log ("shot selected"); Gun.                    SetActive (TRUE); Kinfe.                SetActive (FALSE);                                           } if (HitInfo.collider.gameObject.tag = = "Knife") {//Ibid.                                                Debug.Log ("knife selected"); Gun.                        SetActive (FALSE); Kinfe.                                     SetActive (TRUE); }} Weaponmenu.setactivE (false); }                                                    }    }

Demo

http://download.csdn.net/detail/ystistheking/9550100

HTC Vive Game Toggle Weapon function Ideas and demo (unity,c#)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.