Переглянути джерело

弓箭手攻击距离随机

SZAND\msx_2 1 рік тому
батько
коміт
e51c463ec0

+ 4 - 0
ActionTowerDefense/Assets/Resources/Prefab/Demonic_Arrow.prefab

@@ -574,6 +574,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   owner: {fileID: 0}
+  isCook: 0
   trigObjList: []
   needToChange: 1
   maxLen: 45
@@ -1055,6 +1056,9 @@ MonoBehaviour:
   totalSummonTime: 0.5
   searchState: 0
   attackDistance: 10
+  maxAttackDis: 15
+  minAttackDis: 9
+  needToChange: 1
   canFly: 1
   flyHeight: 0
   flyUpSpeed: 10

+ 2 - 1
ActionTowerDefense/Assets/Resources/Prefab/ESpirits_Cook.prefab

@@ -853,7 +853,7 @@ MonoBehaviour:
   targetCharacter: {fileID: 0}
   beTargetCharacter: []
   searchTrigger: {fileID: 2932762729738363159}
-  targetTypes: 0100000003000000
+  targetTypes: 010000000300000004000000
   canHitFly: 1
   linked: 0
   joint: {fileID: 0}
@@ -1042,6 +1042,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   owner: {fileID: 0}
+  isCook: 1
   trigObjList: []
   needToChange: 0
   maxLen: 0

+ 4 - 0
ActionTowerDefense/Assets/Resources/Prefab/Enemy_Arrow.prefab

@@ -574,6 +574,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   owner: {fileID: 0}
+  isCook: 0
   trigObjList: []
   needToChange: 1
   maxLen: 45
@@ -1054,6 +1055,9 @@ MonoBehaviour:
   jumpSpeed: 10
   searchState: 0
   attackDistance: 10
+  maxAttackDis: 15
+  minAttackDis: 9
+  needToChange: 1
   canFly: 1
   flyHeight: 0
   flyUpSpeed: 10

+ 10 - 0
ActionTowerDefense/Assets/Scripts/Demonic.cs

@@ -11,6 +11,8 @@ public class Demonic : MoveCharacter
     public float totalSummonTime = 0.5f;
     public SearchState searchState;
     public float attackDistance;
+    public float maxAttackDis, minAttackDis;
+    public bool needToChange;
     public bool canFly = false;
     public float flyHeight;
     public float flyUpSpeed = 10;
@@ -21,7 +23,15 @@ public class Demonic : MoveCharacter
 
     private void Awake()
     {
+        
+    }
 
+    private void Start()
+    {
+        if (needToChange)
+        {
+            attackDistance = Random.Range(minAttackDis, maxAttackDis);
+        }
     }
 
     private void OnDisable()

+ 10 - 0
ActionTowerDefense/Assets/Scripts/Enemy.cs

@@ -29,6 +29,8 @@ public class Enemy : MoveCharacter
     public float jumpSpeed = 10;
     public SearchState searchState;
     public float attackDistance;
+    public float maxAttackDis, minAttackDis;
+    public bool needToChange;
     public bool canFly = false;
     public float flyHeight;
     public float flyUpSpeed = 10;
@@ -73,6 +75,14 @@ public class Enemy : MoveCharacter
 
     }
 
+    private void Start()
+    {
+        if (needToChange)
+        {
+            attackDistance = Random.Range(minAttackDis, maxAttackDis);
+        }
+    }
+
     public void OnDisable()
     {
         EnemyCreater.instance.OnEnemyRecycle(this);

+ 8 - 0
ActionTowerDefense/Assets/Scripts/SearchTrigger.cs

@@ -7,6 +7,7 @@ using UnityEngine.TextCore.Text;
 public class SearchTrigger : MonoBehaviour
 {
     public Character owner;
+    public bool isCook;
 
     public List<BeSearchTrigger> trigObjList;
 
@@ -75,6 +76,13 @@ public class SearchTrigger : MonoBehaviour
         List<Character> list = new List<Character>();
         for (int i = 0; i < trigObjList.Count; i++)
         {
+            if (isCook)
+            {
+                if(trigObjList[i].owner.cooks.Exists(T => T == owner.gameObject))
+                {
+                    continue;
+                }
+            }
             if (trigObjList[i].owner.tag == "Demonic" && HasTargetType(targetTypes, TargetType.Demonic)
                 || trigObjList[i].owner.tag == "Tower" && HasTargetType(targetTypes, TargetType.Tower)
                 || trigObjList[i].owner.tag == "Player" && HasTargetType(targetTypes, TargetType.Player)

+ 51 - 40
ActionTowerDefense/Assets/Scripts/Spirits/ESpirits_Cook.cs

@@ -35,7 +35,7 @@ public class ESpirits_Cook : MonoBehaviour
 
     public float larger;                //顾客变大的程度
 
-    private Character target;
+    public Character target;
     public SearchTrigger searchtrigger;
 
     public GameObject lockEffect;
@@ -92,56 +92,59 @@ public class ESpirits_Cook : MonoBehaviour
     private void TargetInteract()
     {
         target = searchtrigger.GetMinDisTarget(ene.targetTypes, ene.canHitFly);
-        if (state == cookState.sell && (target.gameObject.layer == 7 || target.gameObject.layer == 8 || target.gameObject.layer == 6))
+        if (target != null)
         {
-            if (!isInterval && chuan > 0)
+            if (state == cookState.sell && (target.gameObject.layer == 7 || target.gameObject.layer == 8 || target.gameObject.layer == 6))
             {
-                if (!target.cooks.Exists(T => T == gameObject))
+                if (!isInterval && chuan > 0)
                 {
-                    isInterval = true;
-                    chuan -= 1;
-                    text.text = chuan.ToString();
-                    ani.Play("attack_march", 0, 0);
-                    target.HpUp(value, larger);
-                    target.cooks.Add(gameObject);
-                    //count += 1;
-                    //Instantiate(effect, ga.transform.position, new Quaternion(0, 0, 0, 0), ga.transform);
-                    if (chuan == 0)
+                    if (!target.cooks.Exists(T => T == gameObject))
                     {
-                        ani.Play("charge", 0, 0);
-                        Invoke("ToRush", chargeTime);
+                        isInterval = true;
+                        chuan -= 1;
+                        text.text = chuan.ToString();
+                        ani.Play("attack_march", 0, 0);
+                        target.HpUp(value, larger);
+                        target.cooks.Add(gameObject);
+                        //count += 1;
+                        //Instantiate(effect, ga.transform.position, new Quaternion(0, 0, 0, 0), ga.transform);
+                        if (chuan == 0)
+                        {
+                            ani.Play("charge", 0, 0);
+                            Invoke("ToRush", chargeTime);
+                        }
                     }
                 }
             }
-        }
-        //抓人
-        else if (state == cookState.run)
-        {
-            if (target.gameObject.layer == 6 || target.gameObject.layer == 7)
+            //抓人
+            else if (state == cookState.run)
             {
-                food = target.gameObject;
-                if (food.layer == 7 && !target.isDie)
-                {
-                    //food.GetComponent<Demonic>().ChangeState(CharacterState.Coma);
-                    food.GetComponent<Demonic>().ChangeState(CharacterState.Die);
-                    //cookKillEffect.SetActive(true);
-                    ChangeState(cookState.seize);
-                }
-                else if (food.layer == 6 && !target.isDie)
+                if (target.gameObject.layer == 6 || target.gameObject.layer == 7)
                 {
-                    //food.GetComponent<PlayerController>().ChangeState(CharacterState.Coma);
-                    food.GetComponent<PlayerController>().ChangeState(CharacterState.Die);
-                    //cookKillEffect.SetActive(true);
-                    ChangeState(cookState.seize);
+                    food = target.gameObject;
+                    if (food.layer == 7 && !target.isDie)
+                    {
+                        //food.GetComponent<Demonic>().ChangeState(CharacterState.Coma);
+                        food.GetComponent<Demonic>().ChangeState(CharacterState.Die);
+                        //cookKillEffect.SetActive(true);
+                        ChangeState(cookState.seize);
+                    }
+                    else if (food.layer == 6 && !target.isDie)
+                    {
+                        //food.GetComponent<PlayerController>().ChangeState(CharacterState.Coma);
+                        food.GetComponent<PlayerController>().ChangeState(CharacterState.Die);
+                        //cookKillEffect.SetActive(true);
+                        ChangeState(cookState.seize);
+                    }
+                    chuan = food.GetComponent<Character>().cookNum;
+                    text.text = chuan.ToString();
                 }
-                chuan = food.GetComponent<Character>().cookNum;
-                text.text = chuan.ToString();
             }
-        }
-        //回家卖串
-        else if (state == cookState.back && target.gameObject.layer == 8)
-        {
-            ChangeState(cookState.cook);
+            //回家卖串
+            else if (state == cookState.back && target.gameObject.layer == 8)
+            {
+                ChangeState(cookState.cook);
+            }
         }
     }
 
@@ -273,4 +276,12 @@ public class ESpirits_Cook : MonoBehaviour
             }
         }
     }
+
+    private void FixedUpdate()
+    {
+        if (isAct)
+        {
+            TargetInteract();
+        }
+    }
 }