// Update is called once per frame void Update() { //if (isGrounded()) time = 0.0f; if (time > 0) { time -= 0.0f * Time.deltaTime; } else //Explosion creation code happens here! { //No natural explosion if scatter bombs if (attributes.scatter > 0) { //Scatter bombs for (int i = 0; i < attributes.scatter + 1; i++) { GameObject miniBomb = Instantiate(gameObject, transform.position, transform.rotation); //Offset newer bombs a little (randomly) miniBomb.transform.position += new Vector3(Random.Range(-5.0f, 5.0f), 0.0f, Random.Range(-5.0f, 5.0f)); //Make the mini bomes actually mini miniBomb.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); //Make newer bomb components equal to this bomb Bomb miniBombClass = miniBomb.GetComponent <Bomb>(); miniBombClass = miniBomb.GetComponent <Bomb>(); miniBombClass.attributes = attributes; miniBombClass.time = 2.0f; miniBombClass.attributes.explosionScaleLimit /= 1.5f; //Make scatter bombs half as strong as normal miniBombClass.attributes.damage /= 2.0f; //Prevent them from inifnitely creating more miniBombClass.attributes.scatter = 0; } Destroy(gameObject); return; } //Explode! Create an explosion object and destroy self GameObject bombExplosion = Instantiate(newExplosion, transform.position, transform.rotation); //Modify that explosion based on explosion variables ExplosionScale newExplosionClass = bombExplosion.GetComponent <ExplosionScale>(); newExplosionClass.explosionAttributes = attributes; if (First) { ThrowingPlayer.transform.position = gameObject.transform.position; newExplosionClass.explosionAttributes.damage = 0.0f; Renderer rend = bombExplosion.GetComponent <Renderer>(); rend.material.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 0.5f)); newExplosionClass.firstBomb = true; Player p = ThrowingPlayer.GetComponent <Player>(); p.firstThrow = false; } Destroy(gameObject); } }
// Use this for initialization void Start() { Debug.Log("Explosion started"); //scaleSpeed = new Vector3(4.0f, 4.0f, 4.0f); //scaleLengthLimit = 10.0f; expanding = true; //extraLifetime = 3.0f; particleEmitters = new GameObject[explosionAttributes.smoke]; //Smoke particles for (int i = 0; i < explosionAttributes.smoke; i++) { particleEmitters[i] = Instantiate(emitterObjectReferences[0], transform.position, new Quaternion(0.0f, 0.0f, 0.0f, 0.0f)); } //Recolour explosion if bigger radius if (explosionAttributes.explosionScaleLimit > 15.0f) { Renderer rend = GetComponent <Renderer>(); rend.material.SetColor("_Color", new Color(0.6f, 0.0f, 0.0f, 0.5f)); } if (explosionAttributes.blackhole > 0) { pullTowards = true; //Special purply colour Renderer rend = GetComponent <Renderer>(); rend.material.SetColor("_Color", new Color(0.0f, 0.0f, 1.0f, 0.5f)); //Blackhole will deal less damage but also last around longer. And of course it gets an extra pull radius. (Good for combining with other things like fire!) explosionAttributes.damage = explosionAttributes.damage / 1.2f; //A blackhole even gets an additional larger invisible explosion that won't damage, but will pull (if statement makes sure its not infinitely spawning more) if (explosionAttributes.damage != 0.0f) { explosionAttributes.explosionLifetime += (1.0f * explosionAttributes.blackhole); GameObject suctionObject = Instantiate(gameObject); ExplosionScale suction = suctionObject.GetComponent <ExplosionScale>(); suction.explosionAttributes = explosionAttributes; suction.explosionAttributes.damage = 0.0f; suction.explosionAttributes.fire = 0; suction.explosionAttributes.freeze = 0; suction.explosionAttributes.scatter = 0; suction.explosionAttributes.smoke = 0; //Pull radius is bigger the more blackhole materials are added suction.explosionAttributes.explosionScaleLimit = explosionAttributes.explosionScaleLimit * (1.5f + (0.25f * suction.explosionAttributes.blackhole)); suctionObject.transform.localScale = transform.localScale * 1.75f; suctionObject.GetComponent <MeshRenderer>().enabled = false; } } /* * //play bomb sounds depending on bomb type * if (explosionAttributes.fire > 0) * { * AudioSource.PlayClipAtPoint(fireExplosion, transform.position); * } * else if (explosionAttributes.freeze > 0) * { * AudioSource.PlayClipAtPoint(iceExplosion, transform.position); * } * else * { * randExplodeSound = Random.RandomRange(0, 3); * if (randExplodeSound == 0) * { * AudioSource.PlayClipAtPoint(explosion1, transform.position); * } * else if (randExplodeSound == 1) * { * AudioSource.PlayClipAtPoint(explosion2, transform.position); * } * else if (randExplodeSound == 2) * { * AudioSource.PlayClipAtPoint(explosion3, transform.position); * } * else * { * AudioSource.PlayClipAtPoint(explosion4, transform.position); * } * }*/ }