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]; tgtList[i].ApplyEffect(attInst); } } } } else { if (hitUnit != null && hitUnit.IsCreep()) { attInstance.tgtUnit = hitUnit; hitUnit.ApplyEffect(attInstance); } } }
IEnumerator MineRoutine() { LayerMask maskTarget = 1 << LayerManager.LayerCreep(); while (true) { if (!dead && !IsInConstruction()) { Collider[] cols = Physics.OverlapSphere(thisT.position, GetAttackRange(), 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) { ObjectPoolManager.Spawn(soPrefab, thisT.position, thisT.rotation); } Dead(); } } yield return(new WaitForSeconds(0.1f)); } }
//called in every frame, execute if there's an ability is selected and pending target selection //use only mouse input atm. void SelectAbilityTarget() { if (selectedAbilityID < 0) { return; } //only cast on terrain and platform LayerMask mask = 1 << LayerManager.LayerPlatform(); int terrainLayer = LayerManager.LayerTerrain(); if (terrainLayer >= 0) { mask |= 1 << terrainLayer; } Ability ability = abilityList[selectedAbilityID]; if (ability.singleUnitTargeting) { if (ability.targetType == Ability._TargetType.Hybrid) { mask |= 1 << LayerManager.LayerTower(); mask |= 1 << LayerManager.LayerCreep(); } else if (ability.targetType == Ability._TargetType.Friendly) { mask |= 1 << LayerManager.LayerTower(); } else if (ability.targetType == Ability._TargetType.Hostile) { mask |= 1 << LayerManager.LayerCreep(); } } #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 Unit targetUnit = null; if (Input.touchCount >= 1) { Camera mainCam = Camera.main; if (mainCam != null) { Ray ray = mainCam.ScreenPointToRay(Input.touches[0].position); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask)) { currentIndicator.position = hit.point + new Vector3(0, 0.1f, 0); validTarget = true; if (ability.singleUnitTargeting) { targetUnit = hit.transform.GetComponent <Unit>(); if (targetUnit != null) { currentIndicator.position = targetUnit.thisT.position; } else { validTarget = false; } } } else { validTarget = false; } } } else { if (validTarget) { ActivateAbility(ability, currentIndicator.position, targetUnit); } else { GameControl.DisplayMessage("Invalid target for ability"); } ClearSelectedAbility(); } #else Camera mainCam = Camera.main; if (mainCam != null) { Ray ray = mainCam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask)) { currentIndicator.position = hit.point + new Vector3(0, 0.1f, 0); Unit targetUnit = null; validTarget = true; if (ability.singleUnitTargeting) { targetUnit = hit.transform.GetComponent <Unit>(); if (targetUnit != null) { currentIndicator.position = targetUnit.thisT.position; } else { validTarget = false; } } if (Input.GetMouseButtonDown(0)) { if (validTarget) { ActivateAbility(ability, currentIndicator.position, targetUnit); ClearSelectedAbility(); } else { GameControl.DisplayMessage("Invalid target for ability"); } } } } if (Input.GetMouseButtonDown(1)) { ClearSelectedAbility(); } #endif }
IEnumerator AOETowerRoutine() { if (CurrentStat.customMask > -1) { TargetMask = CurrentStat.customMask; } else if (targetMode == _TargetMode.Hybrid) { LayerMask mask1 = 1 << LayerManager.LayerCreep(); LayerMask mask2 = 1 << LayerManager.LayerCreepF(); TargetMask = mask1 | mask2; } else if (targetMode == _TargetMode.Air) { TargetMask = 1 << LayerManager.LayerCreepF(); } else if (targetMode == _TargetMode.Ground) { TargetMask = 1 << LayerManager.LayerCreep(); } while (true) { yield return(new WaitForSeconds(GetCooldown())); while (stunned || IsInConstruction()) { yield return(null); } Collider[] cols = Physics.OverlapSphere(thisT.position, GetAttackRange(), TargetMask); if (cols.Length > 0) { Transform soPrefab = GetShootObjectT(); if (soPrefab != null) { ObjectPoolManager.Spawn(soPrefab, thisT.position, thisT.rotation); } //SendMessage("OnAttackTargetStarted", SendMessageOptions.DontRequireReceiver); //print("AOE attack"); for (int i = 0; i < cols.Length; i++) { Unit unit = cols[i].transform.GetComponent <Unit>(); //damage all units in its range if (unit == null && !unit.dead) { continue; } AttackInstance attInstance = new AttackInstance(); attInstance.srcUnit = this; attInstance.tgtUnit = unit; attInstance.Process(); unit.ApplyEffect(attInstance); } } else { //SendMessage("OnAttackTargetStopped", SendMessageOptions.DontRequireReceiver); //print("AOE stopped"); } } }