/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Damage() { //-------------- if (dead == false) { amountDamage += currentDamage; if (amountDamage > amountLife * 0.75f && runAwayAdditionally == false) { runAway = true; } if (amountDamage > amountLife) { if (Mathf.Sqrt(Class_Controller.SqrMagnitudeToPlayer(thisTransform)) < thisAudioSource.maxDistance) { thisAudioSource.pitch = Random.Range(0.7f, 1.2f); thisAudioSource.panStereo = Random.Range(-0.1f, 0.1f); thisAudioSource.PlayOneShot(soundsFx[Random.Range(2, 5)], Random.Range(0.6f, 1.0f)); } dead = true; speed = 0; aiAgr = attack = contusion = false; Class_AI.amountEnemyAIs -= 1; if (injuredByPlayer == true) { Class_AI.RandomMinerals(thisTransform, true); PlayerPrefs.SetInt("DestroyedEnemies", PlayerPrefs.GetInt("DestroyedEnemies") + 1); } } } //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static IEnumerator CheckChildCount(Transform thisTransform, GameObject gameObject) { //-------------- int counter0 = 0; while (true) { yield return(delay0); if (thisTransform.childCount == 0) { ChunkCubesPool.TakeCube(gameObject); } else if (thisTransform.childCount > 0 && thisTransform.childCount <= 2) { if (counter0++ >= 75) { counter0 = 0; if (Class_Controller.SqrMagnitudeToPlayer(thisTransform) > 250000) { ChunkCubesPool.TakeCube(gameObject); } } } } //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Damage() { //-------------- if (dead == false) { amountDamage += currentDamage; if (amountDamage > amountLife * 0.75f && runAwayAdditionally == false) { runAway = true; } if (amountDamage > amountLife) { if (Mathf.Sqrt(Class_Controller.SqrMagnitudeToPlayer(thisTransform)) < thisAudioSource.maxDistance) { thisAudioSource.pitch = Random.Range(1.15f, 1.4f); thisAudioSource.panStereo = Random.Range(-0.1f, 0.1f); thisAudioSource.PlayOneShot(soundsFx[Random.Range(2, 5)], Random.Range(0.9f, 1.0f)); } dead = true; speed = 0; aiAgr = attack = contusion = false; Class_AI.amountFriendlyAIs -= 1; } } //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// IEnumerator OnEnableCoroutine() { //-------------- if (trigger0 == true) { distance = Mathf.Sqrt(Class_Controller.SqrMagnitudeToPlayer(thisTransform)); } //-------------- if (trigger0 == true && distance < thisAudioSource.maxDistance) { countCurent++; yield return(null); if (countCurent < 10) { thisAudioSource.clip = soundsFx[Random.Range(0, soundsFx.Length)]; thisAudioSource.pitch = Random.Range(audioPitch.x, audioPitch.y); thisAudioSource.volume = Random.Range(audioVolume.x, audioVolume.y); thisAudioSource.Play(); while (thisAudioSource.isPlaying == true) { yield return(delay0); } } countCurent--; } else { if (randomTime == true) { time = Random.Range(minTime, maxTime); } else { time = minTime; } yield return(new WaitForSeconds(time)); } //-------------- ExplosionParticlesPool.TakeExplosionParticle(gameObject); //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// IEnumerator Optimization() { //-------------- while (planetDestroyed == false) { yield return(delay0); planetDestroyed = planet.GetComponent <Planet>().planetDestroyed; if (Class_Controller.SqrMagnitudeToPlayer(thisTransform) < sqrtDistanceLod) { rotationLod = false; } else { rotationLod = true; } } //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void SeesEnemiesOrPlayer() { //-------------- if (counter22++ >= 5) { counter22 = 0; distanceToPlayer = Class_Controller.SqrMagnitudeToPlayer(thisTransform); enemiesIsVisible = Class_AI.EnemiesIsVisible(thisTransform, atackDistance0, 14); playerIsVisible = distanceToPlayer < atackDistancePow0 && Class_Interface.maskerEnabled == false && Class_Controller.playerAlive == true; if (Class_Interface.tamingEnabled == false && speedTaming != 1) { speedTaming = 1; } else if (speedTaming != 0.5f) { speedTaming = 0.5f; } } //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void SeesEnemiesOrPlayer() { //-------------- if (counter22++ >= 5) { counter22 = 0; distanceToPlayer = Class_Controller.SqrMagnitudeToPlayer(thisTransform); enemiesIsVisible = Class_AI.EnemiesIsVisible(thisTransform, atackDistance0, 10); if (counter12++ > 6 && helpPlayerOn == true && playerIsVisible == false && enemiesIsVisible == false && distanceToPlayer < atackDistance2) { counter12 = 0; playerIsVisible = Random.Range(1, helpVariation) == 1; if (playerIsVisible == true) { randomAtackDistance = Random.Range(0.85f, 1.15f); } } } //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// IEnumerator Optimization() { //-------------- while (true) { yield return(delay0); if (visible == true && counter0 != 0) { counter0 = 0; } if (counter0++ >= 7) { DebrisesPool.TakeDebris(gameObject); } if (Class_Controller.SqrMagnitudeToPlayer(thisTransform) > distanceLod) { DebrisesPool.TakeDebris(gameObject); } } //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static IEnumerator FakeUpdate(Transform thisTransform, Rigidbody thisRigidbody, GameObject gameObject, LineRenderer thisLineRenderer) { //-------------- int counter0 = 0; thisRigidbody.isKinematic = false; thisRigidbody.detectCollisions = true; thisLineRenderer.enabled = false; //-------------- while (counter0++ < 60) { yield return(delay0); if (thisLineRenderer.enabled == true) { thisLineRenderer.enabled = false; } float sqrMagnitudeToPlayer = Class_Controller.SqrMagnitudeToPlayer(thisTransform); if (sqrMagnitudeToPlayer < 10000) { if (counter0 != 0) { counter0 = 0; } if (thisRigidbody.isKinematic == true) { thisRigidbody.isKinematic = false; } if (thisRigidbody.detectCollisions == false) { thisRigidbody.detectCollisions = true; } if (Class_Controller.mineralsCollector == true && sqrMagnitudeToPlayer < 1600) { thisRigidbody.AddForce((Class_Controller.playerPosition - thisTransform.position).normalized * 800, ForceMode.Acceleration); if (thisLineRenderer.enabled == false) { thisLineRenderer.enabled = true; } thisLineRenderer.SetPosition(0, thisTransform.position); thisLineRenderer.SetPosition(1, Class_Controller.playerPosition); } } else if (sqrMagnitudeToPlayer >= 10000 && sqrMagnitudeToPlayer > 250000) { if (thisRigidbody.isKinematic == false) { thisRigidbody.isKinematic = true; } if (thisRigidbody.detectCollisions == true) { thisRigidbody.detectCollisions = false; } } else if (sqrMagnitudeToPlayer >= 250000) { MineralsPool.TakeMineral(gameObject); } } //-------------- MineralsPool.TakeMineral(gameObject); //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Shooting(float distanceC) { //-------------- if (distanceC < atackDistancePow0 && distanceC > atackDistance1) { speed = 7 * speedBehavior; if (aiAgr == true || attack == true) { aiAgr = attack = false; } } else if (distanceC < atackDistance1 && distanceC > atackDistance2) { speed = 20 * speedBehavior; if (aiAgr == true || attack == true) { aiAgr = attack = false; } } else if (distanceC < atackDistance2 && distanceC > atackDistance3) { speed = 5 * speedBehavior; if (aiAgr == true) { aiAgr = false; } if (counter5++ > counter19) { counter5 = 0; counter19 = Random.Range(15, 25); attack = true; } else if (attack == true) { attack = false; } } else if (distanceC < atackDistance3 && distanceC > atackDistance4 * randomAtackDistance) { speed = 3 * speedBehavior; if (Class_Interface.tamingEnabled == false) { aiAgr = true; } if (counter5++ > counter19) { counter5 = 0; counter19 = Random.Range(6, 16); attack = true; } else if (attack == true) { attack = false; } } else if (distanceC < atackDistance4 * randomAtackDistance) { if (dodge == false) { speed = -12 * speedBehavior; } else { speed = 6 * speedBehavior; } if (Class_Interface.tamingEnabled == false) { aiAgr = true; } if (counter5++ > counter19) { counter5 = 0; counter19 = Random.Range(3, 7); attack = true; } else if (attack == true) { attack = false; } } //-------------- if (attack == true && contusion == false && Class_Interface.tamingEnabled == false && dodge == false) { if (Mathf.Sqrt(Class_Controller.SqrMagnitudeToPlayer(thisTransform)) < thisAudioSource.maxDistance) { thisAudioSource.pitch = Random.Range(0.7f, 1.15f); thisAudioSource.panStereo = Random.Range(-0.1f, 0.1f); thisAudioSource.PlayOneShot(soundsFx[Random.Range(0, 2)], Random.Range(0.1f, 0.25f)); } if (weaponSparks != null && weaponSparks.activeSelf == false && lodUpdate0 == false && lodUpdate1 == false) { weaponSparks.SetActive(true); } GameObject bullet = WeaponsPool.GiveWeapons(9); bullet.transform.parent = null; bullet.transform.position = thisTransform.position + (thisTransform.forward * 1.5f); bullet.SetActive(true); bullet.GetComponent <Rigidbody>().AddForce(thisTransform.forward * bulletSpeed); } //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// IEnumerator GenerationBlackHole() { //-------------- material.SetFloat("_HoleSize", 0.7f + (Mathf.Cos(Class_StarSystem.seed * 12.5f) * 0.11f)); Color colorA = new Color(RenderSettings.fogColor.r, RenderSettings.fogColor.g, RenderSettings.fogColor.b, 0.9f); Color colorB = new Color(0.62f, 0.43f, 0.4f, 0.9f); particleMain = crownA.main; particleMain.startColor = new ParticleSystem.MinMaxGradient(colorA, colorB); colorA = new Color(colorA.r * 1.4f, colorA.g * 1.4f, colorA.b * 1.4f, 0.9f); particleMain = crownB.main; particleMain.startColor = new ParticleSystem.MinMaxGradient(colorA, new Color(colorB.r * 1.4f, colorB.g * 1.4f, colorB.b * 1.4f, 0.9f)); colorA = new Color(colorA.r * 1.3f, colorA.g * 1.3f, colorA.b * 1.3f, 0.9f); colorB = new Color(0.9f, 0.4f, 0.4f, 0.9f); particleMain = quasarA.main; particleMain.startColor = new ParticleSystem.MinMaxGradient(colorA, colorB); var particleShape = quasarA.shape; particleShape.radius = Class_StarSystem.SeedAbsCos() * 0.5f; particleShape.angle = 1 + (Mathf.Abs(Mathf.Cos(Class_StarSystem.seed * Class_StarSystem.SeedAbsCos())) * 3); particleMain = quasarB.main; particleMain.startColor = new ParticleSystem.MinMaxGradient(colorA, colorB); particleShape = quasarB.shape; particleShape.radius = Class_StarSystem.SeedAbsCos() * 0.5f; particleShape.angle = 1 + (Mathf.Abs(Mathf.Cos(Class_StarSystem.seed * Class_StarSystem.SeedAbsCos())) * 3); //-------------- thisTransform.localScale = Vector3.one * (Class_StarSystem.SeedAbsCos() + 0.3f) * 0.9f; soundFx.maxDistance = thisTransform.localScale.x * 800; distanceDetectedPlayer = Mathf.Pow(soundFx.maxDistance + 50, 2); float scaleblackHole = (Class_StarSystem.SeedAbsCos() + 0.2f) * 50; thisTransform.rotation = new Quaternion(Class_StarSystem.SeedAbsCos() * 60, Class_StarSystem.SeedAbsCos() * 60, Class_StarSystem.SeedAbsCos() * -60, 0); //-------------- satellitesOrbit.localRotation = Quaternion.Euler(Class_AdditionalTools.PositionSeed(thisTransform, 1.1f) * 15, Class_AdditionalTools.PositionSeed(thisTransform, 2.2f) * 15, Class_AdditionalTools.PositionSeed(thisTransform, 3.3f) * 15); float systemSize = 2 * scaleblackHole / thisTransform.localScale.x; int systemDensity = 7; //-------------- for (int x = -systemDensity; x < systemDensity; x++) { for (int z = -systemDensity; z < systemDensity; z++) { yield return(null); float distance = Vector3.Distance(new Vector3(x, 0, z), Vector3.zero); if (distance < systemDensity && distance > systemDensity * 0.6f) { float xt = (systemSize * 0.5f - 0.5f) + (x * systemSize); float zt = (systemSize * 0.5f - 0.5f) + (z * systemSize); float cosQtObj = Mathf.Cos((11.1f + xt + z) * (10.3f + x + zt) * Class_StarSystem.seed * 0.033f); float lperlinf = Mathf.PerlinNoise(cosQtObj, cosQtObj); if (lperlinf > 0.1f && lperlinf < 0.75f) { GameObject obj = Instantiate(asteroid); Transform tr = obj.transform; obj.GetComponent <Asteroid>().minAmountDetails = 2; obj.GetComponent <Asteroid>().maxAmountDetails = 2; tr.rotation = Random.rotation; tr.localScale = Vector3.one * (1 + (lperlinf * scaleblackHole * 0.8f)); tr.parent = satellitesOrbit; float yt = Mathf.Cos(lperlinf * (lperlinf + xt + zt)) * scaleblackHole; tr.localPosition = new Vector3(xt + (Mathf.Cos(lperlinf * zt) * scaleblackHole), yt, zt + (Mathf.Cos(lperlinf * xt) * scaleblackHole)); obj.SetActive(true); } } } } //-------------- while (Class_Controller.playerAlive == true) { triggerDetectedPlayer = Class_Controller.SqrMagnitudeToPlayer(thisTransform) < distanceDetectedPlayer; if (soundFx.enabled != triggerDetectedPlayer) { soundFx.enabled = triggerDetectedPlayer; } QuasarAColider.SetActive(true); QuasarBColider.SetActive(true); yield return(delay0); QuasarAColider.SetActive(false); QuasarBColider.SetActive(false); yield return(delay0); } //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// IEnumerator Optimization() { //-------------- while (brokenStage0 == false) { yield return(delay0); int planetChildCount = planetCubeTransform.childCount; if (brokenStage1 == false && planetChildCount > 0) { brokenStage1 = true; } if (brokenStage1 == true) { if (planetChildCount < 6 && brokenStage2 == false) { brokenStage2 = true; rotationLod = false; Class_ChunkCube.ParticlesOutOfPool(thisTransform, ExplosionParticlesPool.GiveExplosionParticle(1), planetCubeTransform.localScale.x * Random.Range(0.75f, 1.25f)); while (gravity.transform.childCount != 0) { yield return(null); foreach (Transform child in gravity.transform) { child.transform.parent = null; } } Class_ChunkCube.ParticlesOutOfPool(thisTransform, ExplosionParticlesPool.GiveExplosionParticle(1), planetCubeTransform.localScale.x * Random.Range(0.75f, 1.25f)); yield return(null); gravity.SetActive(false); atmosphere.SetActive(false); forest.SetActive(false); } if (planetChildCount == 0) { brokenStage0 = true; } } if (brokenStage2 == false) { if (Class_Controller.SqrMagnitudeToPlayer(thisTransform) < sqrtDistanceLod) { rotationLod = false; } else { rotationLod = true; } } } //-------------- planetDestroyed = true; Class_PlanetarySystem.listPlanets.Remove(gameObject); planetCube.SetActive(false); collidersToOptimizeDestruction.SetActive(false); //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// IEnumerator Optimization() { //-------------- while (brokenStage0 == false) { yield return(delay0); int moonChildCount = moonCubeTransform.childCount; if (brokenStage1 == false && moonChildCount > 0) { brokenStage1 = true; } if (brokenStage1 == true) { if (moonChildCount < 6 && brokenStage2 == false) { brokenStage2 = true; rotationLod = false; Class_ChunkCube.ParticlesOutOfPool(thisTransform, ExplosionParticlesPool.GiveExplosionParticle(1), moonCubeTransform.localScale.x * Random.Range(0.75f, 1.25f)); while (gravity.transform.childCount != 0) { yield return(null); foreach (Transform child in gravity.transform) { child.transform.parent = null; } } Class_ChunkCube.ParticlesOutOfPool(thisTransform, ExplosionParticlesPool.GiveExplosionParticle(1), moonCubeTransform.localScale.x * Random.Range(0.75f, 1.25f)); yield return(null); gravity.SetActive(false); atmosphere.SetActive(false); } if (moonChildCount == 0) { brokenStage0 = true; } } if (brokenStage2 == false) { if (Class_Controller.SqrMagnitudeToPlayer(thisTransform) < sqrtDistanceLod) { rotationLod = false; } else { rotationLod = true; } } } //-------------- moonCube.SetActive(false); //-------------- }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static IEnumerator GenAsteroid(Transform thisTransform, Transform asteroidCubesTransform, float distanceLod, GameObject asteroidCubes, GameObject lod, int amountAsteroids) { //-------------- for (int i = 0; i < amountAsteroids; i++) { yield return(null); GameObject cubeOutOfPool = ChunkCubesPool.GiveCube(); if (cubeOutOfPool != null) { cubeOutOfPool.layer = 30; Transform cubeOutOfPoolTransform = cubeOutOfPool.transform; cubeOutOfPoolTransform.parent = asteroidCubesTransform; float uvOffsetX = Mathf.Abs(Class_AdditionalTools.PositionSeed(thisTransform, amountAsteroids + i + 1.27f)); cubeOutOfPool.GetComponent <ChunkCube>().uvOffset = new Vector2(uvOffsetX, 0.025f); float cubeOutOfPoolScaleXZ = 0.15f + Mathf.Abs(Class_AdditionalTools.PositionSeed(thisTransform, uvOffsetX + i + 4.13f) * 0.7f); float cubeOutOfPoolY = 0.15f + Mathf.Abs(Class_AdditionalTools.PositionSeed(thisTransform, cubeOutOfPoolScaleXZ + uvOffsetX + i + 1.9f) * 0.7f); cubeOutOfPoolTransform.localScale = new Vector3(cubeOutOfPoolScaleXZ, cubeOutOfPoolY, cubeOutOfPoolScaleXZ); float xt = Class_AdditionalTools.PositionSeed(thisTransform, i + cubeOutOfPoolScaleXZ * 1.241f) * (0.6f - (0.6f * cubeOutOfPoolScaleXZ)); float yt = Class_AdditionalTools.PositionSeed(thisTransform, i + cubeOutOfPoolY * 8.83f) * (0.6f - (0.6f * cubeOutOfPoolY)); float zt = Class_AdditionalTools.PositionSeed(thisTransform, i + cubeOutOfPoolScaleXZ * 3.31f) * (0.6f - (0.6f * cubeOutOfPoolScaleXZ)); cubeOutOfPoolTransform.localPosition = new Vector3(xt, yt, zt); float xr = Class_AdditionalTools.PositionSeed(thisTransform, xt + cubeOutOfPoolScaleXZ * 7.13f) * 20; float yr = Class_AdditionalTools.PositionSeed(thisTransform, yt + cubeOutOfPoolY * 6.93f) * 20; float zr = Class_AdditionalTools.PositionSeed(thisTransform, zt + cubeOutOfPoolScaleXZ * 1.13f) * 20; cubeOutOfPoolTransform.localRotation = Quaternion.Euler(xr, yr, zr); cubeOutOfPool.SetActive(true); } } //-------------- Class_AdditionalTools.UvMesh(lod.GetComponent <MeshFilter>().mesh, 0.4f, 0.025f); while (true) { yield return(delay0); if (asteroidCubes.transform.childCount > 0) { if (Class_Controller.SqrMagnitudeToPlayer(thisTransform) < distanceLod) { asteroidCubes.SetActive(true); lod.SetActive(false); } else { asteroidCubes.SetActive(false); lod.SetActive(true); } } else { thisTransform.gameObject.SetActive(false); } } //-------------- }