Bläddra i källkod

烟雾可以对弓箭手造成影响

LAPTOP-OM1V99U2\永远de小亡灵 1 år sedan
förälder
incheckning
9ceb9bbfb6

+ 30 - 0
ActionTowerDefense/Assets/Scripts/CharacterColliders.cs

@@ -5,6 +5,8 @@ using UnityEngine;
 public class CharacterColliders : MonoBehaviour
 {
     public Character owner;
+    public GameObject smoke;
+    public float hitRate = 1;
 
     private void Awake()
     {
@@ -27,6 +29,34 @@ public class CharacterColliders : MonoBehaviour
 
     public void Attack2ShootEvent(int shootId)
     {
+        if (smoke != null && smoke.activeSelf)
+        {
+            Vector3 pos1 = smoke.transform.position;
+            Vector3 pos2 = transform.position;
+            CapsuleCollider collider = smoke.GetComponent<CapsuleCollider>();
+            if (Vector3.Distance(new Vector3(pos1.x,pos1.y,0),new Vector3(pos2.x,pos2.y,0))
+                <collider.radius)
+            {
+                if (Random.Range(0f, 1f) < hitRate)
+                {
+                    if (owner == null)
+                    {
+                        owner = GetComponentInParent<Character>();
+                    }
+                    owner.AttackShootEvent(2, shootId);
+                }
+                else
+                {
+                    GameObject miss = Instantiate(smoke.GetComponent<SmokeDestroy>().MissUI);
+                    miss.transform.position = transform.position + Vector3.up * 0.5f;
+                }
+                
+                return;
+
+            }
+
+        }
+
         if (owner == null)
         {
             owner = GetComponentInParent<Character>();

+ 8 - 0
ActionTowerDefense/Assets/Scripts/Spirits/SmokeDestroy.cs

@@ -24,6 +24,14 @@ public class SmokeDestroy : MonoBehaviour
         {
             attackTrigger.Miss = MissUI;
             attackTrigger.hitRate = hitRate;
+            return;
+        }
+        CharacterColliders characterColliders = other.GetComponentInParent<CharacterColliders>();
+        
+        if(characterColliders != null && characterColliders.owner.attackType == AttackType.Shoot)
+        {
+            characterColliders.smoke = gameObject;
+            characterColliders.hitRate = hitRate;
         }
     }
 }