Reputation: 1
I am using the Google Cardboard SDK along with Unity 3D to build the first Unity Tutorial (Roll a ball) for Google Cardboard. I need to move the main player ball (the white one in the tutorial) to collect the small yellow cubes.Now,Google Cardboard only allows head tracking along with a single switch (magnetic/conductive foam) out of the box.In order to move the ball,I need to attach a controller.
This is my plan -> Buy a joystick. Connect it to an Arduino. Attach a bluetooth module to the Arduino.
I need to know how to receive bluetooth data in the game. Should the code be inside the main player script's void Update() method?
Any help would be appreciated. Thank You :)
Upvotes: 0
Views: 3305
Reputation: 195
Don't get why you need Arduino.
I made a cardboard game (flight simulator type). bought an Ipega 9028 gamepad from aliexpress. binded it with my android / iphone and thats it. (unless your phone doesnt have bluetooth... in that case you should invest in a new phone not in a new Arduino :) )
in your unity app, you first need to bind the keys and save them in PlayerPrefs, because you have no way of knowing which button / axis translates to which unity button number / axis number.
so in the input manager in unity you need to define all possible buttons and axis for joystick number 1. and then unity, create a key binding menu. there you should have the user click a Bind button for each option (like move, shoot, go up, go down etc..) and once he clicks it you need to have 2 "for loops". one that looks for input on all button numbers (Input.GetButton), and one that looks for input on all joystick axis (Input.GetAxis). according to the names you've created for them in the input manager.
once you detect an input, you should store it's name in the playerPrefs along with the action that it's suppose to bind to.
you should make your users do this once after they install the game. because each gamepad transmits different codes to unity. so for example for the left analog stick, you can't know in advance which axis it will correspond to in unity.
then in your game just read all these values from the playerPrefs on Start() and you will know which input to listen to for each action.
i hope this is clear.
p.s. also get a usb joystick so you will have an easy time testing on your development machine.
Upvotes: 0