I created an animation for my camera to play at the beginning of a level. It works when I press play in the editor. It works if I check ‘Play automatically’. But I want it to work code-driven, which it doesn’t yet. What happens is that it clearly yields for the duration of the clip, then resorts to the normal game which works fine. How can I get the clip to play when my level starts in a code-driven way?
How it’s setup currently is in my gameStateScript (on my empty object named GameState). Basically it tells the mouseLook script to turn off while I run the animation clip (set to play once), then resume mouseLookScript when done.
Here’s the animation component (on MainCamera) paused at start, followed by the relevant excerpts I hoped someone could look at and see if they spot trouble:
[33399-screen+shot+2014-10-07+at+11.27.53+pm.png|33399]
var mainCamera:Camera; //main camera to be used
var mouseLookScript:MouseOrbitCamera; //MouseControl Script for Cam
var cAnim:Animation; //holds animation component of camera.
function Awake()
{
//Instantiate the Main Camera.
Instantiate (mainCamera, levelStartWayPt.transform.position, levelStartWayPt.transform.rotation); //Place the Camera (@waypoint)
cAnim = mainCamera.GetComponent(Animation); //get the animation component
Debug.Log(cAnim); //outputs fine as 'MainCamera(UnityEngine.Animation)'
mouseLookScript = GameObject.FindGameObjectWithTag("MainCamera").GetComponent(MouseOrbitCamera); //assign the mouse look script.
}
function Start()
{
CamIntro(); //plays the intro cinematic.
}
function CamIntro()
{
//INTRO CAMERA
mouseLookScript.enabled = false;//Disable Camera Controls
cAnim.Play("camLevel01Intro");
yield WaitForSeconds(cAnim.clip.length);//When Done...
mouseLookScript.enabled = true;//Re-enable Cam Controls
}