diff --git a/Assets/scripts/Bomb.cs b/Assets/scripts/Bomb.cs index 758f4c62..251199b2 100644 --- a/Assets/scripts/Bomb.cs +++ b/Assets/scripts/Bomb.cs @@ -4,7 +4,7 @@ using UnityEngine; public class Bomb : MonoBehaviour { - public int harm; + public float harm; public GameObject bomb; public float explosionRadius = 5f; // 爆炸半径 public float maxDamage = 100f; // 最大伤害 @@ -23,15 +23,29 @@ public class Bomb : MonoBehaviour float damage = Mathf.Lerp(maxDamage, 0, distance / explosionRadius); //具体伤害 - + if(collider.gameObject.tag=="enemy") + { + Enemy enemy = collider.gameObject.GetComponent(); + enemy.EnemyHpDown(damage); + DesSelf(); + } + if (collider.gameObject.tag == "ore") + { + Ore ore = collider.gameObject.GetComponent(); + ore.OreHpDown(damage); + DesSelf(); + } } } void OnCollisionEnter(Collision collision) { - if (collision.gameObject.CompareTag("Player")) - { - Explode(); - } + Explode(); + } + void DesSelf() + { + //爆炸特效 + + Destroy(this.gameObject); } } diff --git a/Assets/scripts/Bullet.cs b/Assets/scripts/Bullet.cs index 98a8fc50..296cfc00 100644 --- a/Assets/scripts/Bullet.cs +++ b/Assets/scripts/Bullet.cs @@ -7,7 +7,7 @@ public class Bullet : MonoBehaviour public int harm; private void Start() { - Destroy(this.gameObject,1f); + DesSelf(1f); } private void OnCollisionEnter(Collision collision) { @@ -15,16 +15,27 @@ public class Bullet : MonoBehaviour { Enemy enemy = collision.gameObject.GetComponent(); enemy.EnemyHpDown(harm); - Destroy(this.gameObject); + DesSelf(); } if (collision.gameObject.CompareTag("ore")) { Ore ore = collision.gameObject.GetComponent(); ore.OreHpDown(harm); - Destroy(this.gameObject); + DesSelf(); } - - } - + + + void DesSelf() + { + //爆炸特效 + + Destroy(this.gameObject); + } + void DesSelf(float time) + { + //爆炸特效 + + Destroy(this.gameObject, time); + } } diff --git a/Assets/scripts/Enemy.cs b/Assets/scripts/Enemy.cs index c1e210ae..a40d1dd8 100644 --- a/Assets/scripts/Enemy.cs +++ b/Assets/scripts/Enemy.cs @@ -6,7 +6,7 @@ using UnityEngine.AI; public class Enemy : MonoBehaviour { public NavMeshAgent _agent; - public int bloodvolume; + public float bloodvolume; public Transform player; // Start is called before the first frame update void Start() @@ -27,7 +27,7 @@ public class Enemy : MonoBehaviour } } - public void EnemyHpDown(int hp) + public void EnemyHpDown(float hp) { bloodvolume -= hp; } diff --git a/Assets/scripts/Ore.cs b/Assets/scripts/Ore.cs index 1c0ae6cf..2b4cf6c6 100644 --- a/Assets/scripts/Ore.cs +++ b/Assets/scripts/Ore.cs @@ -4,14 +4,14 @@ using UnityEngine; public class Ore : MonoBehaviour { - public int OreHp; + public float OreHp; // Start is called before the first frame update void Start() { } - public void OreHpDown(int hp) + public void OreHpDown(float hp) { if (OreHp <=0) return; OreHp-=hp;