コード例 #1
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     npcMovement    = animator.GetComponent <NpcMovement>();
     transform      = animator.GetComponent <Transform>();
     getDestination = animator.GetComponent <GetDestination>();
     destination    = getDestination.SetDestination();
 }
コード例 #2
0
    void SetRandomDestination()
    {
        // Set destination
        destination   = getDestination.SetDestination();
        destination.z = mainPositionZ;

        SetFacingDirection();
    }
コード例 #3
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        direction             = destination - transform.position;
        npcMovement.direction = direction.normalized;
        float dist = Vector2.Distance(transform.position, destination);

        if (dist <= .1f)
        {
            animator.SetTrigger("Idle");
        }

        if (animator.GetComponentInParent <Rigidbody2D>().velocity != Vector2.zero)
        {
            return;
        }
        getDestination.SetDestination();
    }