Quantcast
Channel: Questions in topic: "issue"
Viewing all articles
Browse latest Browse all 827

Why doesn't my explosive barrel code work?

$
0
0
This code worked twice and then never functioned again. Why? It still plays the particle system and destroys the object, but doesn't damage or apply any force to objects with the Target script, a collider, and a rigidbody. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Explosive : MonoBehaviour { [SerializeField] LayerMask damagableMask; public int damage = 60; public ParticleSystem explosionParticle; public void Explode() { Instantiate(explosionParticle,gameObject.transform.position,gameObject.transform.rotation); explosionParticle.Play(); Collider[] hitColliders = Physics.OverlapSphere(gameObject.transform.position,20f,damagableMask); foreach (var hitCollider in hitColliders) { Target target = hitCollider.transform.GetComponent(); Rigidbody rb = hitCollider.transform.GetComponent(); if(rb != null) { rb.AddExplosionForce(10f,gameObject.transform.position,20f,4f,ForceMode.Impulse); } if(target != null) { target.TakeDamage(damage); } Destroy(gameObject); } } }

Viewing all articles
Browse latest Browse all 827

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>