Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
4
Question by Max-Pixel · Aug 24, 2014 at 10:23 PM · androidvrjava

How to detect Google Cardboard Magnet Pull on Android

Google Cardboard and its knockoffs have a magnet slider that, when pulled, creates enough of a disturbance to be detected by the phone. In the Google Cardboard app, this is used as a way to click. How would I detect this in Unity? Google gives an example here, but it is for Java (native Android SDK development): https://developers.google.com/cardboard/get-started

This is to be used with the Durovis Dive plugin for the stereoscopic rendering.

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 Wojtekgr · Jul 24, 2015 at 03:35 PM 0
Share

hi, I am a bit of a noob when it comes to scripting. How would I use the script? I want my character to start Autowalk when the trigger is pressed.

3 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Max-Pixel · Aug 25, 2014 at 10:45 PM

I was able to figure out the answer on my own, with a bit more work. Hopefully this Question will help others who are also looking for this functionality.

There is a script on GitHub that works flawlessly, right here: https://github.com/CaseyB/UnityCardboardTrigger

Comment
Add comment · Show 5 · Share
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 urhire@yahoo.com · Jan 27, 2015 at 07:17 AM 0
Share

I Don't see any script over there! Can you check that link?

avatar image Max-Pixel · Jan 28, 2015 at 01:19 AM 1
Share

Their master branch is empty, the script is in the feature/Updating_events branch: https://github.com/CaseyB/UnityCardboardTrigger/tree/feature/Updating_events

avatar image SelfishGenome · May 01, 2015 at 09:39 PM 0
Share

Do you need the google cardboard SD$$anonymous$$ to use this or did you get it working with the Dive?

avatar image Max-Pixel · May 02, 2015 at 01:47 AM 0
Share

Nope, this stands on its own. You don't even need to use it with the Dive SD$$anonymous$$: Technically, you could do a bare-bones Unity-Android build with the CardboardTrigger script and it would recognize any sort of sudden nearby magnet activity.

avatar image Ekta-Mehta-D · Jun 08, 2015 at 11:38 AM 0
Share

hii how to use this script?

avatar image
3

Answer by Codest19 · Oct 09, 2015 at 08:01 AM

This may be a little old but it took me awhile to figure out so here it is. The Cardboard SDK has built-in support to get trigger pulls, they are registered as events. You only need to add the event to your script. Add the event with OnEnable() and OnDisable() with the function you wish it to call.

Edit: Adding OnDisable() has odd effects on the sdk. I left it out and everything works well.

 using UnityEngine;
 using System.Collections;
 
 public class Gun : MonoBehaviour {
 
     void OnEnable(){
         Cardboard.SDK.OnTrigger += TriggerPulled;
     }
 
     void OnDisable(){
         Cardboard.SDK.OnTrigger -= TriggerPulled;
     }
 
     void TriggerPulled() {
         Debug.Log("The trigger was pulled!");
     }
 }
 
Comment
Add comment · Share
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
0

Answer by elich11 · Jul 01, 2015 at 10:42 AM

To use the scripts, simply apply a method to the delegate (MyEvent), in this method, you can see I call another script (Mover) method to react to the magnet event.

void myEvent() { Debug.Log("Got magnet event!"); mover.setDoStart(); }

void Awake() { mover = GetComponent ();

     OnCardboardTrigger = myEvent;
     _sensorData = new List<Vector3>(WINDOW_SIZE);
     _offsets = new float[SEGMENT_SIZE];

}

Comment
Add comment · Share
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

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

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Issue installing apk using old Cert 1 Answer

Error Building Android Project 2 Answers

How to get smooth device camera in gearvr like passthrough option? 0 Answers

Loading 8192x8192 textures at runtime on android 0 Answers

Many problems using the new Cardboard unity3D integration 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