- Home /
How to rotate the camera on a button press.
Ok, so i'm trying to make my camera rotate one i press the F button, here's my code that doesn't seem to be working, upon pressing play the camera is constantly spinning. #pragma strict var Flipping = false;
function FlipTimer()
{
Flipping = true;
WaitForSeconds(3);
Flipping = false;
}
function CheckFlip () {
if (Input.GetAxis ("f")){
Invoke("FlipTimer" ,0);
}
}
function Update () {
if (Flipping === true){
transform.Rotate(Vector3.left*9);
}
}
Ideally, i was hoping pressing the button "f" would set the flipping varriable to true, with the if statement in the function update checking to see if this was true. If so it would rotate.
Answer by hellaeon · Aug 30, 2013 at 12:39 PM
Hi frosstt, try using GetKeyUp which will register your f keyboard press after you release it, and without testing your code, this is going to make your camera spin for 3 seconds then stop.
If you want it to turn only when you press f, check out implementing GetKeyDown into your code. If you want to do this try
Function Update()
{
If (Input.GetKeyDown(KeyCode.F))
Transform.Rotate(Vector3.left*9);
}
Your answer
Follow this Question
Related Questions
How to rotate the camera smoothly for just 1 second? 2 Answers
Change characters direction using camera view 0 Answers
Camera in fixed position which rotates with player. 0 Answers
Rotate camera to character angle 0 Answers
World of Warcraft Camera 2 0 Answers