Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityStandardAssets.CrossPlatformInput;
- public class MovePlayer : MonoBehaviour
- {
- int verticalSpeed = 10;
- Rigidbody2D body;
- [SerializeField] GameObject paddleWidth;
- float ScreenWidthInUnits = 16f;
- float yMin = 3f;
- float yMax = 3f;
- // Start is called before the first frame update
- void Start()
- {
- body = GetComponent<Rigidbody2D>();
- LimitMovement();
- }
- // Update is called once per frame
- void Update()
- {
- Move();
- }
- public void Move()
- {
- float controlVert = CrossPlatformInputManager.GetAxis("Vertical");
- Vector2 yPos = new Vector2(0, controlVert * verticalSpeed);
- body.velocity = yPos;
- }
- public void LimitMovement()
- {
- var limitYPos = Mathf.Clamp(paddleWidth.transform.position.y, yMin, yMax) / Screen.height;
- limitYPos = transform.position.y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement