Limiting Drag and Drop

using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour{
	public static int speed = 5;
	Vector3 point;

	void Update(){
		transform.position = new Vector3(Mathf.Clamp(Time.time, -2.5F, 2.5F), 0, 0);
	}
	void OnMouseDrag(){
		point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
		point.y = transform.position.y;
		transform.position = point;

	}
}

This is my code above.

It works witohut Mathf.Clamp thing but when I add Mathf.Clamp gameobject goes right and up.I want to limit drag and drop area.How can I do?

- I don’t want to use y axis and it must be fixed.I’m working with x and z axis.

Thanks!

First of all, you probably shouldn’t use Time.time and 0 as the new position since that does not relate to the old position. It would also make sense to clamp the new position before it is applied, in the OnMouseDrag method. Try the following

 using UnityEngine;
 using System.Collections;

 public class Movement : MonoBehaviour{
     void OnMouseDrag(){
         Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         point.x = Mathf.Clamp(point.x, -2.5f, 2.5f);
         point.y = transform.position.y;
         point.z = Mathf.Clamp(point.z, -2.5f, 2.5f);
         transform.position = point; 
     }
 }