Im making a Pong game and our teacher wants us to use the same script for both the paddles and my question is how do i go about doing that?
Here’s my code for one of the paddles, which works great. Both are the same just different KeyCode.X, i just have to take the other one and put them both in the same script, but they each should control different paddles.
if (Input.GetKey (KeyCode.W)) {
rigidbody2D.velocity = new Vector3 (0, +10, 0);
transform.position = new Vector3 (-9, transform.position.y, transform.position.z);
}
if (Input.GetKey (KeyCode.S)) {
rigidbody2D.velocity = new Vector3 (0, -10, 0);
transform.position = new Vector3 (-9, transform.position.y, transform.position.z);
}
if (!Input.GetKey (KeyCode.W) && !Input.GetKey (KeyCode.S)) {
rigidbody2D.velocity = new Vector3 (0, 0, 0);
}