void Awake() { instance = this; Barrel.SetActive(true); BarrelMesh.SetActive(true); ExplosionParticle.SetActive(false); ExplosionArea.SetActive(false); }
public void Explode() { Player player; CameraController.instance.Shake(); GameObject instance = Instantiate(explosionSound); instance.transform.parent = LevelConfig.instance.effects; Instantiate(explosionEffect, transform.position, Quaternion.identity); Collider[] overlappedColliders = Physics.OverlapSphere(transform.position, radius, ~ignoreExplosion); for (int i = 0; i < overlappedColliders.Length; i++) { Rigidbody rb = overlappedColliders[i].attachedRigidbody; RaycastHit hitData; bool hit = Physics.Raycast(transform.position, overlappedColliders[i].transform.position - transform.position, out hitData, Vector3.Distance(overlappedColliders[i].transform.position, transform.position), ~ignoreMask); //Debug.DrawRay(transform.position, overlappedColliders[i].transform.position - transform.position, Color.yellow, 60); if (hit) { if (hitData.collider.gameObject == overlappedColliders[i].gameObject) { if (rb) { if (rb.TryGetComponent <Player>(out player)) { if (!player.isShielded) { player.ExplosionDie(); } } else { rb.AddExplosionForce(force, transform.position, radius); } ExplosiveBarrel barrel = rb.GetComponent <ExplosiveBarrel>(); if (barrel) { barrel.Explode(); } } } //GameObject inst = new GameObject(); //inst.name = $"{hitData.collider.gameObject == overlappedColliders[i].gameObject}: {overlappedColliders[i].name}"; //inst.transform.position = hitData.point; } } Destroy(gameObject); }
void OnTriggerEnter(Collider other) { if (other.tag == "Player") { // Try and find an PlayerHealth script on the gameobject hit. PlayerHealth playerHealth = other.GetComponent <PlayerHealth>(); // If the PlayerHealth component exist... if (playerHealth != null) { // ... the player should take damage. playerHealth.TakeDamage(damagePerShot); } } else if (other.tag == "Explosive" && !other.isTrigger) { ExplosiveBarrel barrel = other.GetComponent <ExplosiveBarrel>(); barrel.Explode(); } else { // for other objects } //print(other.tag); if (other.tag == "Enemy" || other.tag == "FloatingCrystal" || other.tag == "TriggerEffect" || other.tag == "Sight" || other.tag == "Climat" || other.tag == "BossLegs" || other.tag == "Bullet" || other.tag == "Boss") { // don't destroy it when it's the player shooting (or the bullet will never go out of the player collider...) } else if (other.tag == "Explosive" && other.isTrigger) { // don't destroy if it impacts the trigger collider of an explosive barrel } else { // in all other case destroy it GameObject impactAnim = (GameObject)Instantiate(bulletImpact, this.transform.position, Quaternion.identity); // destroy the anim after 1 sec Destroy(impactAnim, 1.2f); Destroy(this.gameObject); } }
void OnTriggerEnter(Collider other) { if (other.tag == "Enemy") { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage(this); } } else if (other.tag == "BossLegs") { // Try and find an EnemyHealth script on the gameobject hit. BossHealth bossHealth = GameObject.FindGameObjectWithTag("Boss").GetComponent <BossHealth>(); // If the EnemyHealth component exist... if (bossHealth != null) { // ... the enemy should take damage. bossHealth.TakeDamage(this); } } else if (other.tag == "Explosive" && !other.isTrigger) { ExplosiveBarrel barrel = other.GetComponent <ExplosiveBarrel>(); barrel.Explode(); } else if (other.tag == "Barrelwall") { PassWallTrigger passWall = other.GetComponentInParent <PassWallTrigger>(); passWall.PassOnEffect(); } else if (other.tag == "Firewall" && typeOfBullet == BulletType.Ice) { ZoneWall zoneWall = other.GetComponent <ZoneWall>(); zoneWall.DesactivateWall(); } else if (other.tag == "Plantwall" && typeOfBullet == BulletType.Fire) { ZoneWall zoneWall = other.GetComponent <ZoneWall>(); zoneWall.DesactivateWall(); } else { // for other objects } //print(other.tag); if (other.tag == "Player" || other.tag == "FloatingCrystal" || other.tag == "TriggerEffect" || other.tag == "Sight") { // don't destroy it when it's the player shooting (or the bullet will never go out of the player collider...) } else if (other.tag == "Well" && other.isTrigger) { // don't destroy if it impacts the trigger collider of a well } else if (other.tag == "Explosive" && other.isTrigger) { // don't destroy if it impacts the trigger collider of an explosive barrel } else if (other.tag == "Climat") { // Don't destroy the bullet if it's in a climat's box collider } else if ((other.tag == "IceWall" || other.tag == "Firewall" || other.tag == "Plantwall") && other.isTrigger) { // don't destroy if it impacts the trigger collider a destroyed wall } else { // in all other case destroy it GameObject impactAnim = (GameObject)Instantiate(bulletImpact, this.transform.position, Quaternion.identity); // destroy the anim after 1 sec Destroy(impactAnim, 1.2f); Destroy(this.gameObject); } }
public void Add(ExplosiveBarrel explosiveBarrel) { AllBarrels.Add(explosiveBarrel); }
public void Remove(ExplosiveBarrel explosiveBarrel) { AllBarrels.Remove(explosiveBarrel); }