Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PongPaddle : MonoBehaviour
- {
- [SerializeField] private float speed = 5f;
- [Range(1, 2)]
- [SerializeField] private int playerNumber = 1;
- [SerializeField] private float maxY;
- [SerializeField] private float minY;
- private void Update()
- {
- Move();
- }
- private void Move()
- {
- float y = Input.GetAxisRaw("Vertical" + playerNumber);
- float speedDir = y * speed * Time.deltaTime;
- float newY = transform.position.y + speedDir;
- if(newY > minY && newY < maxY)
- {
- transform.position += new Vector3(0, speedDir, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement