hello, i’m new to unity, but i’m trying to making my way with this powerfull engine.
i’m trying to make a 3d game with a first person camera, my player doesn’t need to move, it can only move the camera, to look to the right and look to the left, i have coded that movement with the mouse using c#, but my problem is that i want to avoid the camera rotate out off the bounds that i’m using in game.
it works almost all, but when the camera arrives to the max amount to the right or left the camera stop rotating and it never rotates again.
here is the code that i’m using to let the camera rotate and stop it too
void Update () {
//camera rot
float RotLeftRight = Input.GetAxis("Mouse X");
if (transform.rotation.y>MaxRight || transform.rotation.y<MaxLeft)
{
LastRotation=transform.rotation.y;
//transform.Rotate(0,LastRotation,0);
}
else
{
transform.Rotate(0, RotLeftRight,0);
}
//movement set to 0 to let the player stays on his place
//float ForwardSpeed = Input.GetAxis("Vertical"); //get speed from input axis
Vector3 speed = new Vector3(0,0,0);
CharacterController cc = GetComponent<CharacterController>();
cc.SimpleMove(speed);
}
MaxLeft and MaxRight are declared at the beginning of the class using public to let the variables to be modified from the unity editor.
i tried using LastRotation and use it as a variable to the rotate function, but when the game uses it, it keep rotate continuosly to the left side
can someone help me, point me to the right direction to fix this ?
thanks in advance for all the help.