Advertisement
drakon-firestone

PaddleScript - z ograniczeniami przed wyjściem za planszę

May 8th, 2023
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. public class PongPaddle : MonoBehaviour
  2. {
  3.     [SerializeField] private float speed = 5f;
  4.  
  5.     [Range(1, 2)]
  6.     [SerializeField] private int playerNumber = 1;
  7.  
  8.     [SerializeField] private float maxY;
  9.     [SerializeField] private float minY;
  10.  
  11.     private void Update()
  12.     {
  13.         Move();
  14.     }
  15.  
  16.     private void Move()
  17.     {
  18.         float y = Input.GetAxisRaw("Vertical" + playerNumber);
  19.  
  20.         float speedDir = y * speed * Time.deltaTime;
  21.  
  22.         float newY = transform.position.y + speedDir;
  23.  
  24.         if(newY > minY && newY < maxY)
  25.         {
  26.             transform.position += new Vector3(0, speedDir, 0);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement