public IEnumerator TurretRoutine() { for (int i = 0; i < shootPoints.Count; i++) { if (shootPoints[i] == null) { shootPoints.RemoveAt(i); i -= 1; } } if (shootPoints.Count == 0) { shootPoints.Add(thisT); } yield return(null); while (true) { while (target == null || stunned || IsInConstruction() || !targetInLOS) { yield return(null); } turretOnCooldown = true; float animationDelay = 0; if (playShootAnimation != null) { animationDelay = playShootAnimation(); } if (animationDelay > 0) { yield return(new WaitForSeconds(animationDelay)); } AttackInstance attInstance = new AttackInstance(); attInstance.srcUnit = this; attInstance.tgtUnit = target; attInstance.Process(); for (int i = 0; i < shootPoints.Count; i++) { _shootTf = (Transform)Instantiate(GetShootObjectT(), shootPoints[i].position, shootPoints[i].rotation); _shootObj = _shootTf.GetComponent <ShootObject>(); _shootObj.Shoot(attInstance, shootPoints[i]); if (delayBetweenShootPoint > 0) { yield return(new WaitForSeconds(delayBetweenShootPoint)); } } yield return(new WaitForSeconds(GetCooldown() - animationDelay - shootPoints.Count * delayBetweenShootPoint)); turretOnCooldown = false; } }
public IEnumerator TurretRoutine() { for (int i = 0; i < shootPoints.Count; i++) { if (shootPoints[i] == null) { shootPoints.RemoveAt(i); i -= 1; } } if (shootPoints.Count == 0) { Debug.LogWarning("ShootPoint not assigned for unit - " + unitName + ", auto assigned", this); shootPoints.Add(thisT); } for (int i = 0; i < stats.Count; i++) { if (stats[i].shootObject != null) { ObjectPoolManager.New(stats[i].shootObject.gameObject, 3); } } yield return(null); while (true) { while (target == null || stunned || IsInConstruction() || !targetInLOS) { yield return(null); } turretOnCooldown = true; Unit currentTarget = target; float animationDelay = PlayAnimAttack(); if (animationDelay > 0) { yield return(new WaitForSeconds(animationDelay)); } AttackInstance attInstance = new AttackInstance(); attInstance.srcUnit = this; attInstance.tgtUnit = currentTarget; attInstance.Process(); for (int i = 0; i < shootPoints.Count; i++) { Transform sp = shootPoints[i]; //Transform objT=(Transform)Instantiate(GetShootObjectT(), sp.position, sp.rotation); GameObject sObj = ObjectPoolManager.Spawn(GetShootObject().gameObject, sp.position, sp.rotation); ShootObject shootObj = sObj.GetComponent <ShootObject>(); shootObj.Shoot(attInstance, sp); if (delayBetweenShootPoint > 0) { yield return(new WaitForSeconds(delayBetweenShootPoint)); } } yield return(new WaitForSeconds(GetCooldown() - animationDelay - shootPoints.Count * delayBetweenShootPoint)); if (GameControl.ResetTargetAfterShoot()) { target = null; } turretOnCooldown = false; } }
public IEnumerator TurretRoutine() { for (int i = 0; i < shootPoints.Count; i++) { if (shootPoints[i] == null) { shootPoints.RemoveAt(i); i -= 1; } } if (shootPoints.Count == 0) { Debug.LogWarning("ShootPoint not assigned for unit - " + unitName + ", auto assigned", this); shootPoints.Add(thisT); } for (int i = 0; i < stats.Count; i++) { if (stats[i].shootObjectT != null) { ObjectPoolManager.New(stats[i].shootObjectT.gameObject, 3); } } yield return(null); UnitTower electricitySource; while (true) { // 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]; } // target will shoot so take that energy if (electricitySource != null) { electricitySource.electricityCurrentlyStored -= GetElectricityNeedForShoot(); } while (target == null || stunned || IsInConstruction() || !targetInLOS) { yield return(null); } if (!electricitySource.dead) { Unit currentTarget = target; float animationDelay = 0; if (playShootAnimation != null) { animationDelay = playShootAnimation(); } if (animationDelay > 0) { yield return(new WaitForSeconds(animationDelay)); } AttackInstance attInstance = new AttackInstance(); attInstance.srcUnit = this; attInstance.tgtUnit = currentTarget; attInstance.Process(); for (int i = 0; i < shootPoints.Count; i++) { Transform sp = shootPoints[i]; Transform objT = (Transform)Instantiate(GetShootObjectT(), sp.position, sp.rotation); ShootObject shootObj = objT.GetComponent <ShootObject>(); shootObj.Shoot(attInstance, sp); if (delayBetweenShootPoint > 0) { yield return(new WaitForSeconds(delayBetweenShootPoint)); } } yield return(new WaitForSeconds(GetCooldown() - animationDelay - shootPoints.Count * delayBetweenShootPoint)); } } }