I wanted to implement a unbound mouse cursor which continues on the other side of the screen once it reaches one side. Exactly how Unity GUI enables you to change the value of variables by dragging it, allowing you to drag you mouse to the side endlessly.
I hope that makes sense. Would appreciate any help.
You cannot set the position of the cursor within Unity. To make this happen you would need to link in a call specific to the OS of the target platform (which would require Pro). But you can fake this behavior by hiding the cursor and moving your own object. The following script can be attached to a GUITexture. I found I had to futz with the value a bit and they may need a bit more work.
#pragma strict
var speed = 0.01;
private var tr : Transform;
function Start() {
tr = transform;
Screen.showCursor = false;
}
function Update() {
tr.position.x += Input.GetAxis("Mouse X") * speed;
tr.position.y += Input.GetAxis("Mouse Y") * speed;
Debug.Log(tr.position);
if (tr.position.x >= 1.05)
tr.position.x = 0.00;
else if (tr.position.x <= -0.05)
tr.position.x = 1.00;
else if (tr.position.y >= 1.05)
tr.position.y = 0.00;
else if (tr.position.y <= -0.05)
tr.position.y = 1.00;
}
Note this cursor does not partially wrap, it just disappears form one side and reappears on the other. Also if you will be raycasting or converting the cursor to world coordinates, a GUITexture uses Viewport coordinates. So you will use Camera.ViewportToWorldPoint() or Camera.ViewportToRay() using the position of this game object to make the conversion.