I’m making a Pong clone and I’m attempting to limit the movement of the paddle, but the paddle just continues to move beyond the specified clamp point. I’m not sure what I’m doing wrong here.
using UnityEngine;
using System.Collections;
public class PaddleMovement : MonoBehaviour {
public float speed = 10.0f;
private float minY = -5.0f;
private float maxY = 2.75f;
void Update ()
{
Vector3 pos = transform.position;
float movement = Input.GetAxis("Vertical") * Time.deltaTime * speed;
transform.Translate(new Vector3(0, movement, 0));
pos.y = Mathf.Clamp(transform.position.y, minY, maxY);
}
}