コード例 #1
0
    void Update()
    {
        if (candy.IsDropped() && !eating)          // candy is falling, look for it
        {
            Vector3 candyVector = candy.transform.position - transform.position;
            float   angle       = Vector3.Angle(Vector3.up, candyVector);
            //since Angle gives [0,180] check if it's actually [180, 360]
            if (candyVector.x < 0)             //lefter than wizard
            {
                angle = 360 - angle;
            }

            int frameOffset = 0;             // for far distance, no frame offset
            if (candyVector.magnitude < closeLookDistance)
            {
                frameOffset = 6;                 //switch to close distance frames
            }
            animator.SetAnimationFrame("look", frameOffset + lookFramesClockwise[(int)(angle / 360 * lookFramesClockwise.Length)]);
        }
        else if (animator.GetCurrentAnimation().GetName() == "look")
        {
            animator.PlayAnimation("idle");
        }
    }