스크립트를 이용하여 Animatorcontroller의 Parameters로 설정한 파라미터로 스테이트를 전환합니다.
그럼 이제 전환하는 스크립트를 준비합니다!
using UnityEngine;
public class CharaAnimation : MonoBehaviour
{
Animator animator;
CharacterStatus status;
Vector3 prePosition;
bool isDown = false;
bool attacked = false;
public bool IsAttacked()
{
return attacked;
}
void StartAttackHit()
{
Debug.Log("StartAttackHit");
}
void EndAttackHit()
{
Debug.Log ("EndAttackHit");
}
void EndAttack()
{
attacked = true;
}
void Start ()
{
animator = GetComponent<Animator>();
status = GetComponent<CharacterStatus>();
prePosition = transform.position;
}
void Update ()
{
Vector3 delta_position = transform.position - prePosition;
animator.SetFloat("Speed", delta_position.magnitude / Time.deltaTime);
if(attacked && !status.attacking)
{
attacked = false;
}
animator.SetBool("Attacking", (!attacked && status.attacking));
if(!isDown && status.died)
{
isDown = true;
animator.SetTrigger("Down");
}
prePosition = transform.position;
}
}
이렇게 셋팅합니다.
'프로그래밍일지 (고등학생 - 인문계) > 유니티 3D' 카테고리의 다른 글
적군의 애니메이션을 확인하자! (0) | 2018.09.06 |
---|---|
스크립트로 AnimatorController를 제어! (2/2 ) (0) | 2018.09.05 |
애니메이션 전환! (0) | 2018.09.05 |
애니메이션 이벤트 설정! (0) | 2018.09.05 |
애니메이션 이벤트! (0) | 2018.09.03 |