I’d like to play a “cinematic” when the player collide a cube. So the camera switches, the animation plays once (the camera just make a simple move created on the Animation tab) and then the camera returns to the player. How can I do that ?
Currently, the camera switches, the animation isn’t played and the camera never comes back to the player.
The following script is attached to the cube that fires the animation. Here is what I’ve come up to so far :
using UnityEngine;
using System.Collections;
public class MyWatchCamera : MonoBehaviour {
public GameObject Item;
public Camera MainCamera;
public Camera AnimCamera;
// Use this for initialization
void Start () {
this.renderer.enabled = false;
}
void OnTriggerEnter(Collider other) {
if (other.tag == "Player") {
Item.BroadcastMessage("Trigger");
Destroy(gameObject);
MainCamera.enabled = false;
AnimCamera.enabled = true;
GameObject.Find("Player").GetComponent<CharacterMotor>().canControl = false; // also this line doesn't work, I'm still able to move the player during the animation
AnimCamera.animation.Play("CameraMove");
StartCoroutine(waitEndOfAnimation());
MainCamera.enabled = true;
AnimCamera.enabled = false;
}
}
IEnumerator waitEndOfAnimation() {
yield return new WaitForSeconds(2);
}
}