public void DoOnCast() { base.DoOnCast(); RaycastHit hit; GameObject.Destroy(gameObject.GetComponent <Collider>()); GameObject.Destroy(gameObject.GetComponent <MeshRenderer>()); GameObject.Destroy(gameObject.GetComponent <MeshFilter>()); if (Physics.Raycast(transform.position, transform.up, out hit)) { GameObject effect = Instantiate(effectToBePlaced); effect.transform.position = hit.point; SpellCore effectSpellCore = effect.GetComponent <SpellCore>(); if (effectSpellCore != null) { CopySpellCoreValues(effectSpellCore); if (effectSpellCore.explosionDamage) { ExplosionModifier explosionModifier = new ExplosionModifier(); explosionModifier.applyAffect(effect); if (setOffChildEffects) { effect.GetComponentInChildren <ExplosionEffect>().Explode(); } } if (effectSpellCore.gravity) { GravityModifier gravityModifier = new GravityModifier(); gravityModifier.applyAffect(effect); } if (effectSpellCore.scale.x > 1) { Vector3 effectScale = effect.transform.localScale; effectScale.x *= effectSpellCore.scale.x; effectScale.y *= effectSpellCore.scale.y; effectScale.z *= effectSpellCore.scale.z; effect.transform.localScale = effectScale; } if (effectSpellCore.elementalAlignment != "") { Renderer[] renderers = effect.GetComponentsInChildren <Renderer>(); foreach (Renderer someRenderer in renderers) { if (effectSpellCore.elementalAlignment == "Water") { someRenderer.material.color = Color.blue; } else if (effectSpellCore.elementalAlignment == "Nature") { someRenderer.material.color = Color.green; } else if (effectSpellCore.elementalAlignment == "Fire") { someRenderer.material.color = Color.red; } } } } } GameObject.Destroy(gameObject); }
// Update is called once per frame void Update() { frameTracker++; lifeSpan--; if (frameTracker % spawningPeriod == 0) { System.Random random = new System.Random(); GameObject meteor = GameObject.Instantiate(meteorBallPrefab, new Vector3((float)(random.NextDouble() * 14) + transform.position.x - 7, transform.position.y, (float)(random.NextDouble() * 14) + transform.position.z - 7), new Quaternion()); meteor.GetComponent <Rigidbody>().velocity = new Vector3(0f, -70f, 0f); meteor.GetComponent <Rigidbody>().angularVelocity = new Vector3(((float)random.NextDouble() * 2) - 1, ((float)random.NextDouble() * 2) - 1, ((float)random.NextDouble() * 2) - 1) * 10; spawningPeriod = random.Next(10, 25); meteor.transform.rotation = new Quaternion((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); SpellCore spellCore = meteor.GetComponent <SpellCore>(); CopySpellCoreValues(spellCore); spellCore.hasItBeenCastedYet = true; //spellCore.DoOnCast(); if (spellCore.explosionDamage) { ExplosionModifier explosionModifier = new ExplosionModifier(); explosionModifier.applyAffect(spellCore.gameObject); } if (spellCore.gravity) { GravityModifier gravityModifier = new GravityModifier(); gravityModifier.applyAffect(spellCore.gameObject); } if (spellCore.scale.x > 1) { Vector3 effectScale = spellCore.gameObject.transform.localScale; effectScale.x *= spellCore.scale.x; effectScale.y *= spellCore.scale.y; effectScale.z *= spellCore.scale.z; spellCore.gameObject.transform.localScale = effectScale; } if (spellCore.elementalAlignment != "") { Renderer[] renderers = spellCore.gameObject.GetComponentsInChildren <Renderer>(); Texture newTexture = Resources.Load("Asteroids_Grey") as Texture; foreach (Renderer someRenderer in renderers) { someRenderer.material.SetTexture("_MainTex", newTexture); if (spellCore.elementalAlignment == "Water") { someRenderer.material.color = Color.blue; } else if (spellCore.elementalAlignment == "Nature") { someRenderer.material.color = Color.green; } else if (spellCore.elementalAlignment == "Fire") { someRenderer.material.color = Color.red; } } } frameTracker = 1; } if (lifeSpan <= 0) { Destroy(gameObject); } }