예제 #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)
    {
        animatorRoot = animator.transform.parent;
        enemy        = animator.GetComponent <JiJoo>();
        player       = GameManager.Instance.player;
        rb2D         = enemy.transform.parent.GetComponent <Rigidbody2D>();

        horizontalSpeed = enemy.horizontalSpeed;
        verticalSpeed   = enemy.verticalSpeed;

        dir         = enemy.MoveDirection();
        destination = enemy.gridPosition + dir;
        if (destination.x < 0 || destination.x >= 6 || destination.y < 0 || destination.y >= 6)
        {
            animator.SetTrigger("IdleTrigger");
            return;
        }

        enemy.transform.eulerAngles = new Vector3(0, 0, JiJoo.Vector2ToZAngle(dir));
        velocity = dir * new Vector2(horizontalSpeed, verticalSpeed);
        Debug.Log(destination);
        Vector2 realVector = JiJoo.RealPosition(destination) - JiJoo.RealPosition(enemy.gridPosition);

        time  = Mathf.Abs(realVector.x) / horizontalSpeed + Mathf.Abs(realVector.y) / verticalSpeed;
        timer = 0;
        rb2D.MovePosition(rb2D.position + velocity * Time.deltaTime);
    }
예제 #2
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (destination.x < 0 || destination.x >= 6 || destination.y < 0 || destination.y >= 6)
        {
            animator.SetTrigger("IdleTrigger");
            return;
        }

        rb2D.MovePosition(rb2D.position + velocity * Time.deltaTime);
        if (timer > time)
        {
            Debug.Log("end");
            enemy.gridPosition = destination;
            enemy.transform.parent.transform.localPosition = JiJoo.RealPosition(destination);
            animator.SetTrigger("IdleTrigger");
        }
        timer += Time.deltaTime;
    }