コード例 #1
0
        void Hit()
        {
            hit = true;

            if (hitEffect != null)
            {
                ObjectPoolManager.Spawn(hitEffect, targetPos, Quaternion.identity);
            }

            //thisT.position=targetPos;
            attInstance.impactPoint = targetPos;

            if (attInstance.srcUnit.GetAOERadius() > 0)
            {
                LayerMask mask = attInstance.srcUnit.GetTargetMask();

                Collider[] cols = Physics.OverlapSphere(targetPos, attInstance.srcUnit.GetAOERadius(), mask);
                if (cols.Length > 0)
                {
                    List <Unit> tgtList = new List <Unit>();
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].gameObject.GetComponent <Unit>();
                        if (!unit.dead)
                        {
                            tgtList.Add(unit);
                        }
                    }
                    if (tgtList.Count > 0)
                    {
                        for (int i = 0; i < tgtList.Count; i++)
                        {
                            if (tgtList[i] == target)
                            {
                                target.ApplyEffect(attInstance);
                            }
                            else
                            {
                                AttackInstance attInst = new AttackInstance();
                                attInst.srcUnit = attInstance.srcUnit;
                                attInst.tgtUnit = tgtList[i];
                                attInst.Process();
                                tgtList[i].ApplyEffect(attInst);
                            }
                        }
                    }
                }
            }
            else
            {
                if (target != null)
                {
                    target.ApplyEffect(attInstance);
                }
            }

            ObjectPoolManager.Unspawn(thisObj);
            //Destroy(thisObj);
        }
コード例 #2
0
ファイル: UnitTower.cs プロジェクト: lusia8500/20191111
        IEnumerator AOETowerRoutine()
        {
            if (targetMode == _TargetMode.Hybrid)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                maskTarget = mask1 | mask2;
            }
            else if (targetMode == _TargetMode.Air)
            {
                maskTarget = 1 << LayerManager.LayerCreepF();
            }
            else if (targetMode == _TargetMode.Ground)
            {
                maskTarget = 1 << LayerManager.LayerCreep();
            }

            while (true)
            {
                yield return(new WaitForSeconds(GetCooldown()));

                while (stunned || IsInConstruction())
                {
                    yield return(null);
                }

                Transform soPrefab = GetShootObjectT();
                if (soPrefab != null)
                {
                    Instantiate(soPrefab, thisT.position, thisT.rotation);
                }

                Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                if (cols.Length > 0)
                {
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].transform.GetComponent <Unit>();
                        if (unit == null && !unit.dead)
                        {
                            continue;
                        }

                        AttackInstance attInstance = new AttackInstance();
                        attInstance.srcUnit = this;
                        attInstance.tgtUnit = unit;
                        attInstance.Process();

                        unit.ApplyEffect(attInstance);
                    }
                }
            }
        }
コード例 #3
0
        void FPSHit(Unit hitUnit, Vector3 hitPoint)
        {
            if (attInstance.srcWeapon.GetAOERange() > 0)
            {
                LayerMask mask1 = 1 << TDTK.GetLayerCreep();
                LayerMask mask2 = 1 << TDTK.GetLayerCreepF();
                LayerMask mask  = mask1 | mask2;

                Collider[] cols = Physics.OverlapSphere(hitPoint, attInstance.srcWeapon.GetAOERange(), mask);
                if (cols.Length > 0)
                {
                    List <Unit> tgtList = new List <Unit>();
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].gameObject.GetComponent <Unit>();
                        if (!unit.IsDestroyed())
                        {
                            tgtList.Add(unit);
                        }
                    }
                    if (tgtList.Count > 0)
                    {
                        for (int i = 0; i < tgtList.Count; i++)
                        {
                            AttackInstance attInst = new AttackInstance();
                            attInst.srcWeapon = attInstance.srcWeapon;
                            attInst.tgtUnit   = tgtList[i];
                            attInst.Process();
                            tgtList[i].ApplyEffect(attInst);
                        }
                    }
                }
            }
            else
            {
                if (hitUnit != null && hitUnit.IsCreep())
                {
                    attInstance.tgtUnit = hitUnit;
                    attInstance.Process();
                    hitUnit.ApplyEffect(attInstance);
                }
            }
        }
コード例 #4
0
ファイル: UnitTower.cs プロジェクト: j1mmyto9/TowerDefense
        IEnumerator MineRoutine()
        {
            LayerMask maskTarget = 1 << LayerManager.LayerCreep();

            while (true)
            {
                if (!dead && !IsInConstruction())
                {
                    Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                    if (cols.Length > 0)
                    {
                        Collider[] colls = Physics.OverlapSphere(thisT.position, GetAOERadius(), maskTarget);
                        for (int i = 0; i < colls.Length; i++)
                        {
                            Unit unit = colls[i].transform.GetComponent <Unit>();
                            if (unit == null && !unit.dead)
                            {
                                continue;
                            }

                            AttackInstance attInstance = new AttackInstance();
                            attInstance.srcUnit = this;
                            attInstance.tgtUnit = unit;
                            attInstance.Process();

                            unit.ApplyEffect(attInstance);
                        }

                        Transform soPrefab = GetShootObjectT();
                        if (soPrefab != null)
                        {
                            Instantiate(soPrefab, thisT.position, thisT.rotation);
                        }

                        Dead();
                    }
                }
                yield return(new WaitForSeconds(0.1f));
            }
        }
コード例 #5
0
        void FPSHit(Unit hitUnit, Vector3 hitPoint)
        {
            if(attInstance.srcWeapon.GetAOERange()>0){
                LayerMask mask1=1<<LayerManager.LayerCreep();
                LayerMask mask2=1<<LayerManager.LayerCreepF();
                LayerMask mask = mask1 | mask2;

                Collider[] cols=Physics.OverlapSphere(hitPoint, attInstance.srcWeapon.GetAOERange(), mask);
                if(cols.Length>0){
                    List<Unit> tgtList=new List<Unit>();
                    for(int i=0; i<cols.Length; i++){
                        Unit unit=cols[i].gameObject.GetComponent<Unit>();
                        if(!unit.dead) tgtList.Add(unit);
                    }
                    if(tgtList.Count>0){
                        for(int i=0; i<tgtList.Count; i++){
                            AttackInstance attInst=new AttackInstance();
                            attInst.srcWeapon=attInstance.srcWeapon;
                            attInst.tgtUnit=tgtList[i];
                            attInst.Process();
                            tgtList[i].ApplyEffect(attInst);
                        }
                    }
                }
            }
            else{
                if(hitUnit!=null && hitUnit.IsCreep()){
                    attInstance.tgtUnit=hitUnit;
                    attInstance.Process();
                    hitUnit.ApplyEffect(attInstance);
                }
            }
        }
コード例 #6
0
        IEnumerator AOETowerRoutine()
        {
            if (targetMode == _TargetMode.Hybrid)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                maskTarget = mask1 | mask2;
            }
            else if (targetMode == _TargetMode.Air)
            {
                maskTarget = 1 << LayerManager.LayerCreepF();
            }
            else if (targetMode == _TargetMode.Ground)
            {
                maskTarget = 1 << LayerManager.LayerCreep();
            }

            UnitTower electricitySource;

            while (true)
            {
                yield return(new WaitForSeconds(GetCooldown()));

                while (stunned || IsInConstruction())
                {
                    yield return(null);
                }

                // disable shooting while there is no electricity
                electricitySource = getElectricitySource(GetElectricityNeedForShoot());

                while (electricitySource == null)
                {
                    // Paint deactivated towers black
                    for (int i = 0; i < myRenderers.Length; i++)
                    {
                        myRenderers[i].material.color = new Color(0.2f, 0.2f, 0.2f);
                    }

                    electricitySource = getElectricitySource(GetElectricityNeedForShoot());
                    yield return(null);
                }

                // Restore original color
                for (int i = 0; i < myRenderers.Length; i++)
                {
                    myRenderers[i].material.color = myRenderersColors[i];
                }

                Transform soPrefab = GetShootObjectT();
                if (soPrefab != null)
                {
                    Instantiate(soPrefab, thisT.position, thisT.rotation);
                }

                Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                if (electricitySource != null && !electricitySource.dead && cols.Length > 0)
                {
                    // target will shoot so take that energy
                    electricitySource.electricityCurrentlyStored -= GetElectricityNeedForShoot();

                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].transform.GetComponent <Unit>();
                        if (unit == null && !unit.dead)
                        {
                            continue;
                        }

                        AttackInstance attInstance = new AttackInstance();
                        attInstance.srcUnit = this;
                        attInstance.tgtUnit = unit;
                        attInstance.Process();

                        unit.ApplyEffect(attInstance);
                    }
                }
            }
        }