コード例 #1
0
ファイル: Unit.cs プロジェクト: ledotrong/tower-defense
        protected IEnumerator SupportRoutine()
        {
            supportRoutineRunning = true;

            StartCoroutine(SupportEffectRoutine());

            while (true)
            {
                yield return(new WaitForSeconds(0.1f));

                if (!destroyed)
                {
                    List <Unit> tgtList = new List <Unit>();
                    Collider[]  cols    = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                    if (cols.Length > 0)
                    {
                        for (int i = 0; i < cols.Length; i++)
                        {
                            Unit unit = cols[i].gameObject.GetComponent <Unit>();
                            if (!unit.IsDestroyed())
                            {
                                tgtList.Add(unit);
                            }
                        }
                    }

                    for (int i = 0; i < buffedUnit.Count; i++)
                    {
                        Unit unit = buffedUnit[i];
                        if (unit == null || unit.IsDestroyed())
                        {
                            buffedUnit.RemoveAt(i); i -= 1;
                        }
                        else if (!tgtList.Contains(unit))
                        {
                            unit.UnBuff(GetBuff());
                            buffedUnit.RemoveAt(i); i -= 1;
                        }
                    }

                    for (int i = 0; i < tgtList.Count; i++)
                    {
                        Unit unit = tgtList[i];
                        if (!buffedUnit.Contains(unit))
                        {
                            unit.Buff(GetBuff());
                            buffedUnit.Add(unit);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Unit.cs プロジェクト: LiShuJun-spec/dumingjun
        public IEnumerator SupportRoutine()
        {
            supportRoutineRunning = true;

            LayerMask maskTarget = 0;

            if (subClass == _UnitSubClass.Tower)
            {
                maskTarget = 1 << LayerManager.LayerTower();
            }
            else if (subClass == _UnitSubClass.Creep)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                maskTarget = mask1 | mask2;
            }

            while (true)
            {
                yield return(new WaitForSeconds(0.1f));

                if (!dead)
                {
                    List <Unit> tgtList = new List <Unit>();
                    Collider[]  cols    = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                    if (cols.Length > 0)
                    {
                        for (int i = 0; i < cols.Length; i++)
                        {
                            Unit unit = cols[i].gameObject.GetComponent <Unit>();
                            if (!unit.dead)
                            {
                                tgtList.Add(unit);
                            }
                        }
                    }

                    for (int i = 0; i < buffedUnit.Count; i++)
                    {
                        Unit unit = buffedUnit[i];
                        if (unit == null || unit.dead)
                        {
                            buffedUnit.RemoveAt(i); i -= 1;
                        }
                        else if (!tgtList.Contains(unit))
                        {
                            unit.UnBuff(GetBuff());
                            buffedUnit.RemoveAt(i); i -= 1;
                        }
                    }

                    for (int i = 0; i < tgtList.Count; i++)
                    {
                        Unit unit = tgtList[i];
                        if (!buffedUnit.Contains(unit))
                        {
                            unit.Buff(GetBuff());
                            buffedUnit.Add(unit);
                        }
                    }
                }
            }
        }