Advertisement
Guest User

Untitled

a guest
Jul 29th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityStandardAssets.CrossPlatformInput;
  5.  
  6. public class MovePlayer : MonoBehaviour
  7. {
  8. int verticalSpeed = 10;
  9. Rigidbody2D body;
  10. [SerializeField] GameObject paddleWidth;
  11. float ScreenWidthInUnits = 16f;
  12. float yMin = 3f;
  13. float yMax = 3f;
  14.  
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. body = GetComponent<Rigidbody2D>();
  19. LimitMovement();
  20. }
  21.  
  22. // Update is called once per frame
  23. void Update()
  24. {
  25.  
  26. Move();
  27.  
  28. }
  29.  
  30. public void Move()
  31. {
  32.  
  33.  
  34. float controlVert = CrossPlatformInputManager.GetAxis("Vertical");
  35. Vector2 yPos = new Vector2(0, controlVert * verticalSpeed);
  36. body.velocity = yPos;
  37.  
  38.  
  39. }
  40.  
  41. public void LimitMovement()
  42. {
  43.  
  44. var limitYPos = Mathf.Clamp(paddleWidth.transform.position.y, yMin, yMax) / Screen.height;
  45. limitYPos = transform.position.y;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement