Hey guys,
I was wondering how I would restrict how far the mouse can go on the screen... I was thinking about using mathf.clamp, but I don't really know how... Anyway, if you guys can help, that would be great!
//Written By/For Gibson Bethke
var crosshairTexture : Texture2D;
function Update () {
Screen.showCursor = false;
}
function OnGUI () {
var mousePos = Event.current.mousePosition;
GUI.DrawTexture( Rect( mousePos.x - (crosshairTexture.width/2),
mousePos.y - (crosshairTexture.height/2),
crosshairTexture.width,
crosshairTexture.height), crosshairTexture);
}
Just incase I wasn't clear, I want the mouse to stop before it hits the sides of the screen, much like this (but with the mouse):
//Written By/For Gibson Bethke
var normalMoveSpeed : float = 3.125;
var topMoveSpeed : float = 6.25;
var currentSpeed : float = 3.125;
function Update () {
var down = Vector3(0, -1, 0);
if(Input.GetButton("Jump")) {
currentSpeed = topMoveSpeed;
}else{
currentSpeed = normalMoveSpeed;
}
if(Input.GetButton("W")) {
transform.Translate(Vector3.up * currentSpeed);
}
if(Input.GetButton("A")) {
transform.Translate(Vector3.left * currentSpeed);
}
if(Input.GetButton("S")) {
transform.Translate(Vector3.down * currentSpeed);
}
if(Input.GetButton("D")) {
transform.Translate(Vector3.right * currentSpeed);
}
var xMove : float = Input.GetAxis("Horizontal") * Time.deltaTime * 20;
transform.Translate(Vector3(xMove,0,0));
transform.position.x = Mathf.Clamp(transform.position.x, 300, 1700);
var zMove : float = Input.GetAxis("Vertical") * Time.deltaTime * 20;
transform.Translate(Vector3(zMove,0,0));
transform.position.z = Mathf.Clamp(transform.position.z, 300, 1700);
}
-Thanks so much for your help!
P.s. Both the scripts work, the top one is what I have so far