this code here would be far better if you didnt see the mouse. but when the mouse is locked it dosent work.
how do i get around it?
p.s. feel free to make this code look better. it works now, perfectly, but im not sure if its optimized in any way.
private var mousePos : Vector2;
var mouseTex : Texture2D;
var radiusRatio : float = 0.25; // how much of the screen to allow movement over (width)
var relativeMousePosition : Vector2;
var screenCenter : Vector2;
var radius : int;
function Update() {
radius = Screen.width * radiusRatio;
screenCenter = Vector2( Screen.width/2, Screen.height/2);
Screen.lockCursor = true;
relativeMousePosition = Input.mousePosition - screenCenter;
mousePos = Vector2(relativeMousePosition.x +Screen.width/2, -relativeMousePosition.y+Screen.height/2);
if ( (mousePos - screenCenter).magnitude > radius ) {
mousePos = screenCenter + (mousePos-screenCenter).normalized * radius;
}
}
function OnGUI() {
DrawTexCentered( mouseTex, mousePos );
}
function DrawTexCentered( t : Texture2D, p : Vector2 ) {
GUI.DrawTexture( Rect( p.x-t.width * .5, p.y-t.height * .5, t.width, t.height ), t );
}