Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KyleF1997 · Jun 03, 2017 at 11:33 AM · vrweaponswitching

Weapon Switch System for Gear VR Controller

Hi, I'm making a game for the Gear VR that involves a weapon switch system. The two weapons are a sword, and a gun. The sword basically uses the rotation of the controller like a Wii remote if you've ever used one, so the player can swipe, block, etc. The gun is a simple point and shoot.

I'm using a weapon switch system that I've used many times before in normal games, disabling one weapon, enabling another. However with the Gear VR controller, I have to check which hand the player is using (right or left) then disable both weapons in the hand they're not using. This is done using a script on the controller prefab provided by Oculus, I've made some changes: changed the m_model to an array which includes the weapons.

 /// <summary>
     /// The root GameObject that should be conditionally enabled depending on controller connection status.
     /// </summary>
     public GameObject[] m_model;
 
     /// <summary>
     /// The controller that determines whether or not to enable rendering of the controller model.
     /// </summary>
     public OVRInput.Controller m_controller;
 
     private bool m_prevControllerConnected = false;
     private bool m_prevControllerConnectedCached = false;
 
     void Update()
     {
         bool controllerConnected = OVRInput.IsControllerConnected(m_controller);
 
         if ((controllerConnected != m_prevControllerConnected) || !m_prevControllerConnectedCached)
         {
             m_model[0].SetActive(controllerConnected);
             m_model[1].SetActive(controllerConnected);
             m_prevControllerConnected = controllerConnected;
             m_prevControllerConnectedCached = true;
         }
 
         if (!controllerConnected)
         {
             return;
         }
     }

Here's my weapon switch script:

     GameObject weaponSword;
     GameObject weaponGun;
 
     void Update()
     {
 
         if(weaponSword == null || weaponGun == null)
         {
             assignWeapons();
         }
 
         if(OVRInput.GetDown(OVRInput.Button.DpadUp))
         {
             weaponGun.SetActive(true);
             weaponSword.SetActive(false);
         }
 
         if(OVRInput.GetDown(OVRInput.Button.DpadDown))
         {
             weaponSword.SetActive(true);
             weaponGun.SetActive(false);
         }
     }
 
     void assignWeapons()
     {
         weaponSword = GameObject.FindGameObjectWithTag("techSword");
         weaponGun = GameObject.FindGameObjectWithTag("techGun");
 
         Debug.Log("Weapons Assigned " + weaponSword.name + " " + weaponGun.name);
 
         weaponGun.SetActive(false);
     }

The problem is that the gun isn't being disabled after it finds the weapons, and it is finding the weapons (the debug tells as much). I would just expose the variables and assign the game objects in the editor, as that seems to work for some reason, but the thing is, I have to find and activate/disable only the weapons in the right or left hand. So first it checks which hand the controller is being used in (right) then it disables the models for the left hand so there isn't a static model sitting there, then my script populates my game object variables using find with tag (and it does find them, the debug works and shows the correct name) but I'm getting my gun overlapping with my sword.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image greggtwep16 · Jun 04, 2017 at 05:10 AM 0
Share

Why do you have to have 2 sets one for each hand? OVRInput's position is going to take into account which hand is active and position that hand accordingly (and I presume the weapon you have attached to the hand). A gun or a sword is symmetrical so they would not have to swap models regardless of the hand it's attached to.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Weapon Switch Script Help 1 Answer

How to Change a Weapon with tag? 1 Answer

Making Weapon Switching Code more effective. 3 Answers

PhotonNetwork Switching Weapons (network sync) 3 Answers

Weapon Switching 3th Person 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges