How do I make a menu button trigger a camera animation?


I’m having issues with a scene which I plan to use as the main menu for a project. Right now, I have a camera with a panning animation I keyframed in the Animation editor, a menu with a play and quit button on one side of the scene, and a play button with the instructions on how to play the game and a second play button on the other side of the scene. When the play clicks the first play button, I want the camera to animation to play out, panning over to the other area of the scene with the second play button and instructions. Then when the player hits that second play button the game will start etc. etc. etc.

I have a very basic understanding of Java, so understandably I’m having difficulties understanding how to write a script that makes all this happen.

I figured the easiest way to accomplish my goal would be to have the first play button enable the Animator component of the scene camera, initiate a timer that lasts 4 seconds (the animation is only 4 seconds), use an “if” statement to test when the timer has reached 4 seconds, and then have it disable the Animator component at the 4 second mark.

I realize there are probably better ways to do what I want to do, but this is what I got. Any help would be much appreciated! The project I’m working on is very time-sensitive (needs to be finished in two weeks) and the game is mostly done, so if anyone could shoot me a response ASAP, that’d be great.


  1. To write any kind of script you go to Assets>Create>C# or JS, then you double click it from the project window (default text editor is Monodevelop).
  2. You should call your functions from Update() and if you have any graphical GUI 2d content like buttons, labels etc. you should call them from OnGUI().
  3. If your buttons are 3D objects then you can use LookAt() function to change the direction the camera is facing towards your object.
  4. To transition the camera from one place to another you can use Vector3.Lerp() function.
  5. To make the transition smooth you can use the Mathf.SmoothStep() for the last parameter of Lerp.
  6. Also to make the change of LookAt from one target to another smooth you can use that same function (that moves the camera) to move an Empty GameObject (GameObject>Create Empty) from start point to end point and set LookAt target to that Empty GameObject.
  7. To make it happen in certain time (like 4 seconds) you can change the ‘duration’ variable from the last links example.
  8. If you need to do something when the mouse clicks a GameObject you can use OnMouseDown() but you have to attach that script to every object you want to affect.
  9. To attach a script to a GameObject you select it in the hierarchy and click ‘Add Component’ in the inspector.
  10. To change between scenes when play button is pressed you can use Application.LoadLevel() and to add the scenes you save them and drag into File>Build Settings>Scenes in Build.

All links above have both C# and JS examples. I recommand you read the descriptions of these functions to learn what values they recieve and return, after that test each example code separately in a fresh scene with simple objects and once you see them work combine them. Good luck!