I am doing a continuation on Unity’s tutorial Roll A Ball, for a programming class, in which I have two balls that need to be controlled through different key inputs (ideally one being controlled through the arrow keys and the other one controlled by the wasd keys). However, my instructor explicitly said to not use the input manager in Unity. I am at a loss and need help on what I should do.
This code controls a ball, but I need it to be controlled with the wasd keys:
public float speed;
public Text winText;
Vector3 startPos;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody> ();
startPos = transform.position;
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.CompareTag ("Reset")) {
rb.velocity = new Vector3 (0f, 0f, 0f);
rb.angularVelocity = new Vector3(0f, 0f, 0f);
transform.rotation = Quaternion.Euler (new Vector3(0f, 0f, 0f));
transform.position = startPos;
}
if (other.gameObject.CompareTag ("Enemy")) {
rb.velocity = new Vector3 (0f, 0f, 0f);
rb.angularVelocity = new Vector3(0f, 0f, 0f);
transform.rotation = Quaternion.Euler (new Vector3(0f, 0f, 0f));
transform.position = startPos;
}
if (other.gameObject.CompareTag ("Goal")) {
winText.text = "Player 1 wins!";
gameObject.SetActive (false);
other.gameObject.SetActive (false);
}
}
}