- Home /
How to make the camera rotate only when right click is held down on the mouse?
I have been watching this guy on Youtube and he has made a series of tutorials for MMORPG games for unity. I downloaded one of his scripts which he released which was the camera movement however when you left click the camera rotates, When you right click the camera rotates again! I want to make it so it only rotates when the right button is held down to rotate. I know there have been previous answers about it however when i tried the solutions they didnt work cause i must have placed them in the wrong place. This is the camera rotate for my game however it works for both left and right buttons.
// If either mouse buttons are down, let the mouse govern camera position
if (GUIUtility.hotControl == 0)
{
if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
{
//Check to see if mouse input is allowed on the axis
if (allowMouseInputX)
xDeg += Input.GetAxis ("Mouse X") * xSpeed * 0.02;
else
RotateBehindTarget();
if (allowMouseInputY)
yDeg -= Input.GetAxis ("Mouse Y") * ySpeed * 0.02;
//Interrupt rotating behind if mouse wants to control rotation
if (!lockToRearOfTarget)
rotateBehind = false;
}
// otherwise, ease behind the target if any of the directional keys are pressed
else if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0 || rotateBehind)
{
//RotateBehindTarget();
}
}
P.S - I have just started Unity so i have only just made the account however i am willing to share and release my progress to help the community once i am advanced at Unity.
Thanks in advanced.
If you just remove the code for left mouse click then it will not rotate for left click and for this you just have to remove Input.Get$$anonymous$$ouseButton(0) part from line no. 4. It will work with right click only.
Bump! I really need this question to be answered.
Your answer
Follow this Question
Related Questions
Object rotates with camera 2 Answers
Wonky Camera Behaviours 0 Answers
Camera transform not responding after load 0 Answers
I am getting a problem with moving and rotating a camera! 1 Answer
Help with camera snap 1 Answer