본문 바로가기
프로그래밍일지 (고등학생 - 인문계)/유니티 3D

스크립트로 AnimatorController를 제어! (1/2 )

by 단월(Kilo) 2018. 9. 5.

스크립트를 이용하여 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;

}

}

이렇게 셋팅합니다.