- Home /
Camera Animation On Click Help?
Hello! I am creating a game Main Menu, and I need help creating a camera animation. My idea is to make the camera move to another area when I click "Options" (GUI Text).
In my script the "cam" is my main camera that is being animated. The "OptionAnim" is the camera animation itself.
MY PROBLEM : my problem is that the animation plays without the user clicking "Options". my other problem is that the animation keeps looping. (In the inspector...the "play automatically" is turned off).
Please help. Here is my script : (Please post a edited or fixed version with an explanation if you can!
var cam : Camera;
function OnMouseEnter()
{
renderer.material.color = Color.grey ;
}
function OnMouseExit()
{
renderer.material.color = Color.white ;
}
function Start()
{
Animation.WrapMode = WrapMode.Once ;
}
function Update()
{
if (Input.GetMouseButton(0)) ;
cam.animation.Play("OptionAnim");
}
Answer by Anusha · Nov 02, 2012 at 04:19 AM
its very simple mistake... you have a ' ; ' after your if (Input.GetMouseButton(0)) which means your cam.animation.Play("OptionAnim"); is being called every frame!... remove the ' ; '
function Update()
{
if (Input.GetMouseButton(0))
{
cam.animation.Play("OptionAnim");
}
}
Yeah all if, while, else if, etc. Statements should end with a "{" in case you were confused.