private void HorizontalCalc() { // Get button input from controller (name 'buttonLeft') if (VInput.GetButton(player1, "buttonLeft")) { print("Player: " + player1 + " pressed Left"); // Turn car left horizontal += -horizontalAdd; horizontal = Mathf.Clamp(horizontal - horizontalAdd, -1f, 0); } // Get button input from controller (name 'buttonRight') else if (VInput.GetButton(player1, "buttonRight")) { print("Player: " + player1 + " pressed Right"); // Turn car right horizontal = Mathf.Clamp(horizontal + horizontalAdd, 0, 1f); } else if (horizontal > 0) { horizontal = Mathf.Clamp(horizontal - horizontalAdd, -1f, 0); } else if (horizontal < 0) { horizontal = Mathf.Clamp(horizontal + horizontalSlow, horizontal, 0); } }
private void VerticalCalc() { // Get button input from controller (name 'buttonUp') if (VInput.GetButton(player0, "buttonUp")) { print("Player: " + player0 + " pressed Up"); // Move car up rb.AddForce(transform.up * speedForce); } // Get button input from controller (name 'buttonDown') else if (VInput.GetButton(player0, "buttonDown")) { print("Player: " + player0 + " pressed Down"); // Move car down if (rb.velocity.y > -4f) { rb.AddForce(transform.up * -speedForce); } } else if (vertical > 0) { vertical += speedForce; } else if (vertical < 0) { vertical = Mathf.Clamp(vertical + rb.drag, vertical, 0); } }
/// <summary> /// 'MonoBehaviour.Update()' method from Unity /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> private void Update() { // Get button input from controller (name 'buttonUp') if (VInput.GetButton(playerNumber, "buttonUp")) { // Move racket up if (transform.position.y < 4f) { transform.Translate(0f, 0.1f * speed, 0f); } } // Get button input from controller (name 'buttonDown') if (VInput.GetButton(playerNumber, "buttonDown")) { // Move racket down if (transform.position.y > -4f) { transform.Translate(0f, -0.1f * speed, 0f); } } }