IEnumerator CheckDestroy() { int sc = 0; cycles = (int)(Random.value * 20f) + 10; if (isBoss) { cycles += 20; } while (Vector2.Distance(transform.position, CameraFlow.position) < 100) { if (transform.position.y < CameraFlow.getScreenMinBorderY()) { break; } sc++; if (sc > 7) { speed *= 0.75f; sc = 0; } if (Random.value < repositionChance) { if (Random.value > 0.92) { behaviorType = 0; Range = Random.Range(6f, 12f); AdRange = Range * .05f + 1f; shootRange = Random.Range(Range * 1.5f, Range * 2.5f); fleeRange = Range * 0.5f * Random.value; } stayPos = CameraFlow.randomScreenPos(); } if (healthPercent < 0.9f) { cycles--; if (cycles < 0 && Random.value > 0.6) { speed += 3; stayPos = Vector2.down * 100 + Vector2.right * (Random.value - 0.5f) * 200; behaviorType = 1; Range = 1; } } yield return(new WaitForSeconds(1f)); } destroySelf(); }
void Start() { Enemies++; life = GetComponent <UnitLife>(); target = PlayerController.player; fireSystem = GetComponent <FireSystem>(); float maxPowerLevel = RandomEnemies.maxDifficulty; float powerLevel = maxPowerLevel; if (Random.value < RandomEnemies.BossChance) { powerLevel *= 10f; RandomEnemies.BossChance = 0; isBoss = true; //AudioManager.playOnce(AudioManager.instance.bossIsCommingClip); AudioManager.playRepeatedEffect(AudioManager.instance.bossIsCommingClip, 6, 2, 1); } else { powerLevel = maxPowerLevel * (Random.value + 2) * 0.05f; float reducePower = maxPowerLevel * (Random.value + 2) * 0.05f; if (powerLevel > reducePower) { powerLevel = reducePower; } } repositionChance = Random.value * 0.1f; camRatio = Random.value * 0.5f; fireSystem.camRatio = camRatio; difficulty = fireSystem.RandomValues(powerLevel); float vv = (difficulty / RandomEnemies.maxDifficulty); float Rv = 0.75f + .15f * vv; life.life = (difficulty * 2) + 35; life.life = Mathf.Clamp(life.life, RandomEnemies.maxDifficulty + 35, RandomEnemies.maxDifficulty * 20); maxLife = life.life; float scale = Rv < 2.5f ? Rv : 2.5f; transform.localScale = scale * Vector3.one; goldDrop = difficulty * 3 + 5; if (goldDrop > RandomEnemies.maxDifficulty * 10) { goldDrop *= 0.25f + Random.value * 0.75f; } rotationSpeed = 2; behaviorType = 1; Range = 0; fleeRange = 0; speed = Random.value * 4f + 1; if (vv < 1 || Random.value > 0.85) { if (Random.value > 0.7) { behaviorType = 0; Range = Random.Range(6f, 12f); AdRange = Range * .05f + 1f; shootRange = Random.Range(Range * 1.5f, Range * 2.5f); fleeRange = Range * 0.5f * Random.value; } else { suicider = Random.value > vv * 4f ? true : false; if (suicider) { if (Random.value > .5f) { difficulty *= .5f; Range = 0; speed = 3.25f / Rv; speed = Mathf.Clamp(speed, 2.5f, 5f); StartCoroutine(DestroySelf(7.5f)); rotationSpeed = 6f; life.life *= 0.75f; camRatio = 0; } } } } StartCoroutine(damageColliding()); stayPos = CameraFlow.randomScreenPos(); RandomEnemies.liveDifficulty += difficulty; StartCoroutine(CheckDestroy()); life.onGetHitCallback += onGethit; }