Пример #1
0
    void CheckWayPoint(WaypointsBase wp, int listCase)
    {
        #region InitCheck
        if (!_initCheck)
        {
            _lookAtTarget      = wp.lookTowards;
            _overrideAnimation = wp.overrideAnimation;
            _initCheck         = true;
        }
        #endregion

        if (!wp.stopList)
        {
            switch (listCase)
            {
            case 0:
                WaitTimerForEachWP(wp, waypoints);
                break;

            case 1:
                WaitTimerForExtraBehaviors(wp, onAlertExtraBehaviors);
                break;
            }
        }

        #region LookTowards
        if (_lookAtTarget)
        {
            float speedToRotate;

            if (wp.speedToLook < 0.1f)
            {
                speedToRotate = 2;
            }
            else
            {
                speedToRotate = wp.speedToLook;
            }

            Vector3 direction = wp.TargetToLookTo.position - transform.position;
            direction.y = 0;

            float angle = Vector3.Angle(transform.forward, direction);

            if (angle > 0.1f)
            {
                targetRoot = Quaternion.LookRotation(direction);
                transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRoot, Time.deltaTime * wp.speedToLook);
            }
            else
            {
                _lookAtTarget = false;
            }
        }

        #endregion

        #region AnimationOverride
        if (_overrideAnimation)
        {
            if (wp.animationRoutines.Length > 0)
            {
                for (int i = 0; i < wp.animationRoutines.Length; i++)
                {
                    charState.CallFunctionWithString(wp.animationRoutines[i], 0);
                }
            }
            else
            {
                Debug.Log("error");
            }
            _overrideAnimation = false;
        }
        #endregion
    }