I created a cube on a plane.
The cube’s position is (2, 3, 0.5).
Now I added a script to the cube to move the cube to any position when I click on the screen.
var clicked : int = 0;
function OnGUI() {
var e : Event = Event.current;
if(e.button == 0 && e.isMouse){
//Debug.Log("Left Click");
this.clicked = 1;
}
}
function Update () {
if (this.clicked == 1)
{
print(transform.position);
transform.position = Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.5);
this.clicked = 0;
}
}
But the result confused me.
Even when I click 5mm left to the cube I get these new coordinates:
(2.5, 3, 0.5)
BUT also
(211, 257, 0.5)
Why is my mouseclick executed two times?
And why is the second position so far away?