Random moving script not working properly.

I’m extremely new to scripting and have been following these tutorials online.
we have to make a object move to a random position inside of a certain area when clicked on. for some reason it keeps moving it down on the z axis (which I don’t want since i’m using a orthographic camera view).

here is the script so far.

function Update ()



    print("Yes the button works");
	var hit : RaycastHit;
	var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
	if(Physics.Raycast (ray, hit, 100.0))
		if(hit.transform.tag == "enemy")
                      var position =Vector3(Random.Range(-6,6),Random.Range(-4,4),0);
		  hit.transform.position = position;
			print("you hit a object");



If the script is on the cube

var position =Vector3(Random.Range(-6,6),Random.Range(-4,4), transform.position.z);

All fixed :smiley:

var position =Vector3(Random.Range(-6,6),Random.Range(-4,4),-41);

I had to change the z to -41 (were the circle was at default