Ejemplo n.º 1
0
        /// <summary>
        /// Target one player and do in target action.
        /// </summary>
        /// <param name="target"> Target we are following. </param>
        public void TargetOne(Transform target)
        {
            if (!mNavMeshAgent.enabled)
            {
                return;
            }

            if (!IsTargetType())
            {
                return;
            }

            // if target is does not exist, end function call.
            if (target == null)
            {
                JCS_Debug.LogError("The transform you are targeting is null");
                return;
            }

            JCS_3DWalkActionManager wam = JCS_3DWalkActionManager.instance;

            if (mSearchCounter == mSearchCount)
            {
                // reset search count.
                mSearchCounter = 0;

                // exit out of recursive function call...
                return;
            }

            // reset the path every time it request.
            mNavMeshAgent.ResetPath();

            // calculate the distance and range relationship, and find out the
            // position agent are approach to.
            Vector3 targetPos = GetPosByWalkType(target);

            JCS_3DWalkAction overlapped = null;

            if (!mAllowOverlapDestination)
            {
                overlapped = wam.OverlapWithOthers(this, targetPos, mOverlapDistance);
            }

            // set to the destination.
            bool found = false;

            if (!overlapped)
            {
                found = mNavMeshAgent.SetDestination(targetPos);
            }

            ++mSearchCounter;

#if (UNITY_EDITOR)
            this.mFoundPath = found;
#endif

            // if faild, try it again.
            if (!found)
            {
                if (overlapped)
                {
                    TargetOne(overlapped.transform);
                }
                else
                {
                    TargetOne(target);
                }
            }
            else
            {
                this.mTargetDestination = targetPos;

                // if succesed, reset search count.
                mSearchCounter = 0;
            }
        }
Ejemplo n.º 2
0
        private void Start()
        {
            JCS_3DWalkActionManager wam = JCS_3DWalkActionManager.instance;

            wam.AddWalkAction(this);
        }