示例#1
0
        /// <summary>
        /// 指定の座標に、向きをそのままで歩きます。到着したらtrueを返します。
        /// </summary>
        /// <param name="targetX">目的地X座標</param>
        /// <param name="walkSpeed">歩き速度</param>
        /// <returns>結果をAdjustWalkResultで返します。</returns>
        public static AdjustWalkResult AdjustWalk(float targetX, float walkSpeed)
        {
            float dist = targetX - instance.transform.position.x;
            float sign = Mathf.Sign(dist);

            dist = Mathf.Abs(dist);
            AdjustWalkResult reached = AdjustWalkResult.Continue;
            float            step    = walkSpeed * Time.fixedDeltaTime;

            if (dist <= step)
            {
                reached   = AdjustWalkResult.Reach;
                walkSpeed = dist * Time.fixedDeltaTime;
                IsBack    = false;
            }
            else
            {
                // 向きと移動方向が逆ならアニメをバックにする
                IsBack = (sign * forwardVector.x) < -0.5f;
            }
            stellaAnimator.SetBool("Back", IsBack);
            stellaAnimator.SetFloat("VelX", walkSpeed);

            myVelocity.x = walkSpeed * sign;
            instance.Gravity();
            float lastx = instance.transform.position.x;

            instance.Move();

            // 移動していないのでアボート
            if ((reached != AdjustWalkResult.Reach) &&
                (Mathf.Abs(lastx - instance.transform.position.x) < instance.abortMinDistance))
            {
                return(AdjustWalkResult.Abort);
            }

            return(reached);
        }