I’m working on a project and i need to set boundaries on my object, i’ve heard about something called mathf.clamp but i really dont know how to use it
using UnityEngine;
using System.Collections;
public class PaddleControl : MonoBehaviour {
public float speed = 5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.RightArrow))
transform.position += new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
if (Input.GetKey (KeyCode.LeftArrow))
transform.position -= new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
}
}
my xmin-xmax are -2.8 and +2.8
i hope someone can help me.
im still a beginner