This code refuses to work properly. The rotation is changing when I press the mouse down, but it doesn’t keep updating. I assume this is my use of If’s and else if’s but If I use a while it crashes.
#pragma strict
var handmain : Transform;
var cameraMouseLook : MouseLook;
var speed : float = 1.0;
var rotationPressed : boolean;
function Start ()
{
}
function Update ()
{
checkRotation();
}
function checkRotation()
{
var h = speed * Time.deltaTime * Input.GetAxis("Mouse X");
if (Input.GetMouseButtonDown(0))
{
handmain.Rotate(0,h,0); //rotate while button is held
cameraMouseLook.enabled = false; //disable mouselook
rotationPressed = true; //debug
}
else if (Input.GetMouseButtonUp(0))
{
cameraMouseLook.enabled = true; //reenable mouselook
rotationPressed = false; //debug
}
}
If I try this, it crashes.
#pragma strict
var handmain : Transform;
var cameraMouseLook : MouseLook;
var speed : float = 1.0;
var rotationPressed : boolean;
function Start ()
{
}
function Update ()
{
checkRotation();
}
function checkRotation()
{
var h = speed * Time.deltaTime * Input.GetAxis("Mouse X");
do
{
handmain.Rotate(0,h,0); //rotate while button is held
cameraMouseLook.enabled = false; //disable mouselook
rotationPressed = true; //debug
}while (Input.GetMouseButtonDown(0));
//else if (Input.GetMouseButtonUp(0))
{
cameraMouseLook.enabled = true; //reenable mouselook
rotationPressed = false; //debug
}
}