using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimationCamera : MonoBehaviour
{
public Camera animationCamera;
public Camera mainCamera;
Animator _anim;
AnimatorStateInfo currInfo;
float animationnormalizedTime;
private void Start()
{
animationCamera.enabled = false;
mainCamera.enabled = true;
_anim = GetComponent<Animator>();
currInfo = _anim.GetCurrentAnimatorStateInfo(0);
animationnormalizedTime = currInfo.normalizedTime;
}
private void Update()
{
if (currInfo.length == animationnormalizedTime)
{
_anim.CrossFade("Animation_Idle", 0);
}
if (Input.GetKeyDown(KeyCode.C))
{
animationCamera.enabled = !animationCamera.enabled;
mainCamera.enabled = !mainCamera.enabled;
if (animationCamera.enabled)
{
_anim.CrossFade("Animation_Sign", 0);
}
else
{
_anim.CrossFade("Animation_Idle", 0);
}
}
}
public void PlaySignAnimation()
{
animationCamera.enabled = true;
_anim.CrossFade("Animation_Sign", 0);
}
}
I’m trying to use the currInfo.
I want to find the animation clip length and also how much time currently passed since the animation clip started. Then to compare the values and in the end to make it “Animation_Idle”.
Sub question: “Animation_Idle” is a state i created in the Animator window so it will not play anything. But maybe it’s the wrong way to stop animation using Animator. Should i use something else to stop the animation instead using “Animation_Idle” ?