using UnityEngine; using System.Collections; public class Paddle : MonoBehaviour { public string controlStyle; public float thrustSpeed; public float rotationSpeed; Rigidbody rb; // Use this for initialization void Start () { rb = GetComponent(); thrustSpeed = 15f; rotationSpeed = 5f; } // Update is called once per frame void Update () { if (controlStyle == "ARROW") { if (Input.GetKey(KeyCode.LeftArrow)) MoveLeft(); if (Input.GetKey(KeyCode.RightArrow)) MoveRight(); if (Input.GetKey(KeyCode.UpArrow)) TurnLeft(); if (Input.GetKey(KeyCode.DownArrow)) TurnRight(); } else if (controlStyle == "WASD") { if (Input.GetKey(KeyCode.A)) TurnLeft(); if (Input.GetKey(KeyCode.D)) TurnRight(); if (Input.GetKey(KeyCode.W)) MoveUp(); if (Input.GetKey(KeyCode.S)) MoveDown(); } else if (controlStyle == "IJKL") { if (Input.GetKey(KeyCode.J)) MoveLeft(); if (Input.GetKey(KeyCode.L)) MoveRight(); if (Input.GetKey(KeyCode.I)) TurnLeft(); if (Input.GetKey(KeyCode.K)) TurnRight(); } else if (controlStyle == "NUMPAD") { if (Input.GetKey(KeyCode.Keypad4)) TurnLeft(); if (Input.GetKey(KeyCode.Keypad6)) TurnRight(); if (Input.GetKey(KeyCode.Keypad8)) MoveUp(); if (Input.GetKey(KeyCode.Keypad2)) MoveDown(); } rb.velocity *= 0.95f; } void TurnLeft() { transform.Rotate(0, 0, rotationSpeed); } void TurnRight() { transform.Rotate(0, 0, -rotationSpeed); } void MoveLeft() { rb.AddForce(new Vector3(-1, 0, 0) * thrustSpeed); } void MoveRight() { rb.AddForce(new Vector3(1, 0, 0) * thrustSpeed); } void MoveUp() { rb.AddForce(new Vector3(0, 1, 0) * thrustSpeed); } void MoveDown() { rb.AddForce(new Vector3( 0, -1, 0) * thrustSpeed); } }