Browse Source

飞镖碰到墙会掉下来

1243896040 12 giờ trước cách đây
mục cha
commit
10070e9f2f

+ 14 - 4
ActionTowerDefense/Assets/Scripts/Bullet.cs

@@ -38,6 +38,8 @@ public class Bullet : MonoBehaviour
     [ShowIf("@bulletType == BulletType.Boomerang")]
     public AttackTrigger attackTrigger;    
     [ShowIf("@bulletType == BulletType.Boomerang")]
+    public CameraController cameraController;    
+    [ShowIf("@bulletType == BulletType.Boomerang")]
     public Animator attackAni;    
     private Vector3 originalPos;
 
@@ -128,8 +130,11 @@ public class Bullet : MonoBehaviour
                 {
                     velocity.x = 0;
                 }
+                if (transform.position.x <= cameraController.leftBoundary || transform.position.x >= cameraController.rightBoundary)
+                {
+                    velocity.x = 0;
+                }
                 rb.velocity = velocity;
-                attackAni.enabled = false;
             }
             return;
         }
@@ -163,14 +168,20 @@ public class Bullet : MonoBehaviour
                 }
                 else
                 {
+                    Vector3 velocity ;
                     if(transform.position.y > 0.5f)
                     {
-                        rb.velocity = dir * speed * (1 - flyTime / backDuration);
+                        velocity = dir * speed * (1 - flyTime / backDuration);
+                        if(transform.position.x <= cameraController.leftBoundary || transform.position.x >= cameraController.rightBoundary)
+                        {
+                            velocity = Vector3.zero;
+                        }
                     }
                     else
                     {
-                        rb.velocity = Vector3.zero;
+                        velocity = Vector3.zero;
                     }
+                    rb.velocity = velocity;
                 }
                 
             }
@@ -229,7 +240,6 @@ public class Bullet : MonoBehaviour
         if (attackAni)
         {
             attackAni.gameObject.SetActive(true);
-            attackAni.enabled = true;
         }
         isInVain = false;
     }

+ 3 - 0
ActionTowerDefense/Assets/Scripts/Skills/BoomerangWeaponController.cs

@@ -9,6 +9,7 @@ public class BoomerangWeaponController : SpecialSkills
     [LabelText("×Óµ¯ÊýÁ¿")] public int bulletNum;
     [LabelText("½Ç¶È")] public float angleRange;
     [LabelText("ʱ¼ä¼ä¸ô")] public float timeInterval;
+    public CameraController cameraController;
     public float backDuration;
     public float stopDuration;
     public float maxFlytime;
@@ -35,6 +36,7 @@ public class BoomerangWeaponController : SpecialSkills
         {
             outBullet.Add(null);
         }
+        cameraController = GameObject.Find("View").GetComponent<CameraController>();
     }
     public override void Attack()
     {
@@ -71,6 +73,7 @@ public class BoomerangWeaponController : SpecialSkills
             float angle;
             Bullet bullet = PoolManager.Instantiate(bulletObj).GetComponent<Bullet>();
             bullet.BoomerangWeaponController = this;
+            bullet.cameraController = cameraController;
             bullet.backDuration = backDuration;
             bullet.stopDuration = stopDuration;
             bullet.maxFlyTime = maxFlytime;