// Update is called once per frame void Update() { Random.seed = System.DateTime.Now.Millisecond; float xpos = Random.Range(-0.5f, 0.5f); float ypos = Random.Range(-2.0f, 2.0f); Vector3 exp_pos = new Vector3(transform.position.x + xpos, transform.position.y + ypos, 0); GameObject newExplosion = GameObject.Instantiate(explosionPrefab, exp_pos, transform.rotation); TimePassed += Time.deltaTime; if (TimePassed > TimeofDeath) { Vector3 targetVector = new Vector3(400, 0, 0); playerObj.GetComponent <Rigidbody2D>().AddForce(targetVector); GameObject bigExplosion = GameObject.Instantiate(explosionPrefab, transform.position, transform.rotation); bigExplosion.transform.localScale = new Vector3(7, 7, 7); soundEffects.PlayExplosion1(); GameObject.Destroy(this.gameObject); } }
public void ShipTrigger2DColliderEnter(Collider2D other) { if (other.gameObject.tag == "Goal") { levelController.OnGoalEnter(); } else if (other.gameObject.tag == "BlackHole") { Debug.Log("Destroyed by black hole"); GameObject boom = GameObject.Instantiate(explosionPrefab); boom.transform.localScale = new Vector3(4, 4, 4); boom.transform.position = transform.position; levelController.EnteredBlackHole(); soundEffects.PlayExplosion2(); GameObject.Destroy(this.gameObject); } else if (other.gameObject.tag == "Missile") { if (shieldOn) { GameObject boom = GameObject.Instantiate(explosionPrefab); //Direction in which the missile explosion will push the player: Vector3 targetDir = new Vector3(-1, 0, 0); //The explosion wil push the player backwards //Get the strength of the explosion from the missile object: float explosionStrength = other.gameObject.GetComponent <MissileController>().explosionStrength; //Apply a force of strength explosionStrength to the player object GetComponent <Rigidbody2D>().AddForce(targetDir * explosionStrength); boom.transform.localScale = new Vector3(4, 4, 4); boom.transform.position = transform.position; GameObject.Destroy(other.gameObject); shieldOn = false; shieldObject.SetActive(false); soundEffects.PlayExplosion2(); } else { Debug.Log("Destroyed by missile"); GameObject boom = GameObject.Instantiate(explosionPrefab); boom.transform.localScale = new Vector3(4, 4, 4); boom.transform.position = transform.position; levelController.DestroyedByMissile(); GameObject.Destroy(other.gameObject); GameObject.Destroy(this.gameObject); soundEffects.PlayExplosion1(); } } else if (other.gameObject.tag == "Shield") { soundEffects.PlayShieldSound(); GameObject.Destroy(other.gameObject); shieldOn = true; shieldObject.SetActive(true); } else if (other.gameObject.tag == "Fuel") { soundEffects.PlayFuelSound(); GameObject.Destroy(other.gameObject); fuel += 50; uI.UpdateFuelGauge(); } }