Ver Fonte

子弹碰墙销毁及最大距离销毁

wulifu há 1 ano atrás
pai
commit
5fadfe0298

+ 1 - 0
ActionTowerDefense/Assets/Resources/Prefab/Arrow.prefab

@@ -238,6 +238,7 @@ MonoBehaviour:
   bulletType: 0
   isGetTarget: 0
   speed: 20
+  maxDistance: 10
 --- !u!54 &8541051486027365006
 Rigidbody:
   m_ObjectHideFlags: 0

+ 17 - 0
ActionTowerDefense/Assets/Scripts/Bullet.cs

@@ -19,6 +19,8 @@ public class Bullet : MonoBehaviour
     public BulletType bulletType;
     public bool isGetTarget = false;
     public float speed;
+    public float maxDistance;
+    Vector3 startPos;
 
     private void Awake()
     {
@@ -26,8 +28,18 @@ public class Bullet : MonoBehaviour
         rb = GetComponent<Rigidbody>();
     }
 
+    private void FixedUpdate()
+    {
+        if ((transform.position - startPos).magnitude >= maxDistance)
+        {
+            isGetTarget = true;
+            gameObject.SetActive(false);
+        }
+    }
+
     public void BeShoot(Character own, Vector3 shootPos, Vector3 dir, int dmg, Vector3 fc)
     {
+        startPos = shootPos;
         transform.position = shootPos;
         transform.right = -dir;
         gameObject.SetActive(true);
@@ -40,6 +52,11 @@ public class Bullet : MonoBehaviour
 
     private void OnTriggerEnter(Collider other)
     {
+        if (other.CompareTag("Plane"))
+        {
+            isGetTarget = true;
+            gameObject.SetActive(false);
+        }
         if (isGetTarget)
         {
             return;