IEnumerator Move()
        {
            Reset(true);

            yield return(new WaitForSeconds(delayBeforeStart));

            StartCoroutine(EmitRoutine());

            while (true)
            {
                //move to next point, return true if reach
                if (MoveToPoint(indicatorT, subPath[subWaypointID]))
                {
                    subWaypointID += 1;                                                 //sub waypoint reach, get the next subwaypoint
                    if (subWaypointID >= subPath.Count)                                 //if reach subpath destination, get subpath for next waypoint
                    {
                        subWaypointID = 0;
                        waypointID   += 1;
                        if (waypointID >= path.GetPathWPCount())                        //if reach path destination, reset to starting pos
                        {
                            Reset();
                        }
                        else                                                                                                                            //else get next subpath
                        {
                            subPath = path.GetWPSectionPath(waypointID);
                        }
                    }
                }

                yield return(null);
            }
        }
Exemple #2
0
        public override void FixedUpdate()
        {
            base.FixedUpdate();

            if (!stunned && !dead)
            {
                if (MoveToPoint(subPath[subWaypointID]))
                {
                    subWaypointID += 1;
                    if (subWaypointID >= subPath.Count)
                    {
                        subWaypointID = 0;
                        waypointID   += 1;
                        if (waypointID >= path.GetPathWPCount())
                        {
                            ReachDestination();
                        }
                        else
                        {
                            subPath = path.GetWPSectionPath(waypointID);
                        }
                    }
                }
            }
        }
Exemple #3
0
        public override void FixedUpdate()
        {
            base.FixedUpdate();

            if (!stunned && !destroyed)
            {
                if (MoveToPoint(subPath[subWaypointID]))
                {
                    subWaypointID += 1;
                    if (subWaypointID >= subPath.Count)
                    {
                        subWaypointID = 0;
                        waypointID   += 1;
                        if (waypointID >= path.GetPathWPCount())
                        {
                            ReachDestination();
                        }
                        else
                        {
                            SetSubPath(path.GetWPSectionPath(waypointID));
                        }
                    }
                }

                /*
                 * if(!path.IsLinearPath()){
                 *      if(MoveToPoint(subPath[subWaypointID])){
                 *              subWaypointID+=1;
                 *              if(subWaypointID>=subPath.Count){
                 *                      subWaypointID=0;
                 *                      waypointID+=1;
                 *                      if(waypointID>=path.GetPathWPCount()){
                 *                              ReachDestination();
                 *                      }
                 *                      else{
                 *                              subPath=path.GetWPSectionPath(waypointID);
                 *                      }
                 *              }
                 *      }
                 * }
                 * else{
                 *      if(MoveToPoint(path.GetWaypointPos(waypointID))){//path.wpList[waypointID].position)){
                 *              waypointID+=1;
                 *              //~ if(waypointID>=path.wpList.Count){
                 *              if(path.ReachEndOfPath(waypointID)){
                 *                      ReachDestination();
                 *              }
                 *      }
                 * }
                 */
            }
        }
Exemple #4
0
 void ReachDestination()
 {
     if (path.loop)
     {
         if (onDestinationE != null)
         {
             onDestinationE(this);
         }
         subWaypointID = 0;
         waypointID    = path.GetLoopPoint();
         subPath       = path.GetWPSectionPath(waypointID);
     }
     else
     {
         dead = true;
         if (onDestinationE != null)
         {
             onDestinationE(this);
         }
         float delay = 0;
         if (animCreep != null)
         {
             delay = animCreep.PlayDestination();
         }
         StartCoroutine(_ReachDestination(delay));
     }
 }
Exemple #5
0
        public override void FixedUpdate()
        {
            base.FixedUpdate();

            if (!stunned && !destroyed)
            {
                if (!path.IsLinearPath())
                {
                    if (MoveToPoint(subPath[subWaypointID]))
                    {
                        subWaypointID += 1;
                        if (subWaypointID >= subPath.Count)
                        {
                            subWaypointID = 0;
                            waypointID   += 1;
                            if (waypointID >= path.GetPathWPCount())
                            {
                                ReachDestination();
                            }
                            else
                            {
                                subPath = path.GetWPSectionPath(waypointID);
                            }
                        }
                    }
                }
                else
                {
                    if (MoveToPoint(path.wpList[waypointID].position))
                    {
                        waypointID += 1;
                        if (waypointID >= path.wpList.Count)
                        {
                            ReachDestination();
                        }
                    }
                }
            }
        }
Exemple #6
0
        //parent unit is for unit which is spawned from destroyed unit
        public void Init(PathTD p, int ID, int wID, UnitCreep parentUnit = null)
        {
            Init();

            path       = p;
            instanceID = ID;
            waveID     = wID;

            float dynamicX = Random.Range(-path.dynamicOffset, path.dynamicOffset);
            float dynamicZ = Random.Range(-path.dynamicOffset, path.dynamicOffset);

            pathDynamicOffset = new Vector3(dynamicX, 0, dynamicZ);
            thisT.position   += pathDynamicOffset;

            if (parentUnit == null)
            {
                waypointID    = 1;
                subWaypointID = 0;
                subPath       = path.GetWPSectionPath(waypointID);
            }
            else
            {
                //inherit stats and path from parent unit
                waypointID    = parentUnit.waypointID;
                subWaypointID = parentUnit.subWaypointID;
                subPath       = parentUnit.subPath;

                fullHP     = parentUnit.fullHP * parentUnit.spawnUnitHPMultiplier;
                fullShield = parentUnit.fullShield * parentUnit.spawnUnitHPMultiplier;
                HP         = fullHP; shield = fullShield;
            }

            distFromDestination = CalculateDistFromDestination();

            if (type == _CreepType.Offense)
            {
                StartCoroutine(ScanForTargetRoutine());
                StartCoroutine(TurretRoutine());
            }
            if (type == _CreepType.Support)
            {
                StartCoroutine(SupportRoutine());
            }
        }
		//parent unit is for unit which is spawned from destroyed unit
		public void Init(PathTD p, int ID, int wID, UnitCreep parentUnit=null){
			Init();
			
			path=p;
			instanceID=ID;
			waveID=wID;
			
			float dynamicX=Random.Range(-path.dynamicOffset, path.dynamicOffset);
			float dynamicZ=Random.Range(-path.dynamicOffset, path.dynamicOffset);
			pathDynamicOffset=new Vector3(dynamicX, 0, dynamicZ);
			thisT.position+=pathDynamicOffset;
			
			if(parentUnit==null){
				waypointID=1;
				subWaypointID=0;
				subPath=path.GetWPSectionPath(waypointID);
			}
			else{
				//inherit stats and path from parent unit
				waypointID=parentUnit.waypointID;
				subWaypointID=parentUnit.subWaypointID;
				subPath=parentUnit.subPath;
				
				fullHP=parentUnit.fullHP*parentUnit.spawnUnitHPMultiplier;
				fullShield=parentUnit.fullShield*parentUnit.spawnUnitHPMultiplier;
				HP=fullHP; shield=fullShield;
			}
			
			distFromDestination=CalculateDistFromDestination();
			
			if(type==_CreepType.Offense){
				StartCoroutine(ScanForTargetRoutine());
				StartCoroutine(TurretRoutine());
			}
			if(type==_CreepType.Support){
				StartCoroutine(SupportRoutine());
			}
		}
Exemple #8
0
        //parent unit is for unit which is spawned from destroyed unit
        public void Init(PathTD p, int ID, int wID, UnitCreep parentUnit = null)
        {
            Init();

            path       = p;
            instanceID = ID;
            waveID     = wID;

            float dynamicX = Random.Range(-path.dynamicOffset, path.dynamicOffset);
            float dynamicZ = Random.Range(-path.dynamicOffset, path.dynamicOffset);

            pathDynamicOffset = new Vector3(dynamicX, 0, dynamicZ);
            thisT.position   += pathDynamicOffset;

            if (parentUnit == null)
            {
                waypointID    = 1;
                subWaypointID = 0;
                subPath       = path.GetWPSectionPath(waypointID);
            }
            else
            {
                //inherit stats and path from parent unit
                waypointID    = parentUnit.waypointID;
                subWaypointID = parentUnit.subWaypointID;
                subPath       = parentUnit.subPath;

                defaultHP = parentUnit.defaultHP * parentUnit.spawnUnitHPMultiplier;
                HP        = GetFullHP();

                defaultShield = parentUnit.defaultShield * parentUnit.spawnUnitHPMultiplier;
                shield        = GetFullShield();
            }

            distFromDestination = CalculateDistFromDestination();

            if (type == _CreepType.Offense)
            {
                maskTarget = 1 << TDTK.GetLayerTower();
                StartCoroutine(ScanForTargetRoutine());
                StartCoroutine(TurretRoutine());
            }
            if (type == _CreepType.Support)
            {
                LayerMask mask1 = 1 << TDTK.GetLayerCreep();
                LayerMask mask2 = 1 << TDTK.GetLayerCreepF();
                maskTarget = mask1 | mask2;

                StartCoroutine(SupportRoutine());
            }

            int rscCount = ResourceManager.GetResourceCount();

            while (valueRscMin.Count < rscCount)
            {
                valueRscMin.Add(0);
            }
            while (valueRscMin.Count > rscCount)
            {
                valueRscMin.RemoveAt(valueRscMin.Count - 1);
            }
            while (valueRscMax.Count < rscCount)
            {
                valueRscMax.Add(0);
            }
            while (valueRscMax.Count > rscCount)
            {
                valueRscMax.RemoveAt(valueRscMax.Count - 1);
            }

            PlayAnimSpawn();
        }