Time for action – adding button features
Kindly perform the following steps to add button features to our marble:
Add one new line each to the OUYA and non-OUYA code for applying a jump force to the rigidbody of our marble. The
Update
function will now look as follows:void Update () { #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR moveVector.x = -Input.acceleration.y + Input.GetAxis("Horizontal"); moveVector.z = -Input.acceleration.x + Input.GetAxis("Vertical); if(Input.GetKeyDown(KeyCode.Space)) { moveVector.y = 50.0f; } else { moveVector.y = 0.0f; } #else //OUYA-specific code goes here moveVector.x = -Input.acceleration.y + OuyaInput.GetAxis(OuyaAxis.LX, OuyaPlayer.P01); moveVector.z = -Input.acceleration.x + OuyaInput.GetAxis(OuyaAxis.LY, OuyaPlayer.P01); if(Input.GetButtonDown("Jump")) moveVector.y = 50.0f; else moveVector.y = 0.0f; #endif rigidbody.AddForce(moveVector * speed * Time.deltaTime); }
The non...