Procházet zdrojové kódy

敌方刺客每隔一段时间冲刺

LAPTOP-OM1V99U2\永远de小亡灵 před 1 rokem
rodič
revize
827308bdff

+ 48 - 15
ActionTowerDefense/Assets/Resources/Prefab/ESpirits_Assassin.prefab

@@ -182,13 +182,18 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   time: 0
-  CD: 5
-  hateDistance: 0
+  attackCD: 5
+  readyCD: 1
+  hateDistance: 10
   state: 0
-  playerController:
-  - {fileID: 0}
-  - {fileID: 0}
   enemy: {fileID: -677743004047987606}
+  rb: {fileID: 2437299196472462355}
+  distance: 0
+  dashEffect: {fileID: 2254593709981819441}
+  moveSpeed: 25
+  offset: 2
+  targetDir: {x: 0, y: 0, z: 0}
+  dashTime: 0.8
 --- !u!54 &2437299196472462355
 Rigidbody:
   m_ObjectHideFlags: 0
@@ -235,11 +240,11 @@ MonoBehaviour:
   totalHp: 100
   hp: 0
   attack1Infos:
-  - damage: 50
-    attackDir: {x: -1, y: 0, z: 0}
-    force: 1000
-    changeHurt: 0
-    repelValue: 50
+  - damage: 400
+    attackDir: {x: 2, y: 1, z: 0}
+    force: 100
+    changeHurt: 1
+    repelValue: 100
   attack2Infos:
   - damage: 50
     attackDir: {x: -1, y: 0, z: 0}
@@ -247,7 +252,7 @@ MonoBehaviour:
     changeHurt: 0
     repelValue: 50
   attackTriggers:
-  - {fileID: 2280520615464243483, guid: aaf35db4e76c3004fb462f102cf8535f, type: 3}
+  - {fileID: 4347565098670608659}
   attackType: 0
   bulletPrefab: {fileID: 0}
   shootPos: []
@@ -269,7 +274,7 @@ MonoBehaviour:
   foot: {fileID: 2437299196663985756}
   extraRiseGravity: -28.8
   extraFallGravity: -14.4
-  moveSpeed: 5
+  moveSpeed: 40
   beRepelValue: 0
   totalBeRepelValue: 30
   weakTime: 0
@@ -287,15 +292,15 @@ MonoBehaviour:
   minRotateSpeed: 5
   floatTime: 20
   outlineMats:
-  - {fileID: 2100000, guid: 7d50f910288e95b4285a5fb549c94fe6, type: 2}
+  - {fileID: 2100000, guid: eb0e26c1a9cf9a14799273e742b98d21, type: 2}
   id: 0
   jumpSpeed: 9
   searchState: 0
   attackDistance: 1.5
   canFly: 0
   attackRatio: 0
-  maxMoveSpeed: 6
-  minMoveSpeed: 5
+  maxMoveSpeed: 30
+  minMoveSpeed: 30
   dropSoul: 3
   soulPrefab: {fileID: 1723151111827507807, guid: e2b65aa482f2f1447a4074208d72b778, type: 3}
   soulStartSpeed: 30
@@ -782,6 +787,7 @@ GameObject:
   - component: {fileID: 1658938184312316380}
   - component: {fileID: 4979172509264116742}
   - component: {fileID: 8257178686841521685}
+  - component: {fileID: 2254593709981819441}
   m_Layer: 0
   m_Name: DashAttackTrigger
   m_TagString: Untagged
@@ -833,6 +839,33 @@ Rigidbody:
   m_Interpolate: 0
   m_Constraints: 126
   m_CollisionDetection: 0
+--- !u!114 &2254593709981819441
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 8175746555017464802}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 028d37216b47ca446ba0037910919e25, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  canHit: 0
+  isEnemy: 1
+  isDash: 0
+  isDashAttack: 0
+  attackInfo:
+    damage: 0
+    attackDir: {x: 0, y: 0, z: 0}
+    force: 0
+    changeHurt: 0
+    repelValue: 0
+  beHitTriggers: []
+  enemy: []
+  offset: 2
+  rushEffect: {fileID: 7473170563405908938, guid: 8ad3c225050205945b10657aa300afd6, type: 3}
+  targetY: 1
 --- !u!1 &8203964573996106666
 GameObject:
   m_ObjectHideFlags: 0

+ 13 - 10
ActionTowerDefense/Assets/Resources/Prefab/Spirits_Assassin.prefab

@@ -190,8 +190,6 @@ MonoBehaviour:
   dashAttackEffect: {fileID: 0}
   offset: 2
   dashEffect: {fileID: 5670168015807601097}
-  dir: {x: 2, y: 1, z: 0}
-  force: 1000
 --- !u!114 &2437299196472462353
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -222,11 +220,11 @@ MonoBehaviour:
   totalHp: 1000
   hp: 0
   attack1Infos:
-  - damage: 50
-    attackDir: {x: -2, y: 2, z: 0}
-    force: 10000
+  - damage: 200
+    attackDir: {x: 2, y: 1, z: 0}
+    force: 100
     changeHurt: 1
-    repelValue: 52
+    repelValue: 100
   attack2Infos:
   - damage: 50
     attackDir: {x: -2, y: 1, z: 0}
@@ -829,10 +827,15 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   canHit: 0
-  damage: 100
-  force: {x: 0, y: 0, z: 0}
-  changeHurt: 1
-  repelValue: 200
+  isEnemy: 0
+  isDash: 0
+  isDashAttack: 0
+  attackInfo:
+    damage: 0
+    attackDir: {x: 0, y: 0, z: 0}
+    force: 0
+    changeHurt: 0
+    repelValue: 0
   beHitTriggers: []
   enemy: []
   offset: 2

+ 92 - 12
ActionTowerDefense/Assets/Scripts/Spirits/ESpirits_Assassin.cs

@@ -3,46 +3,126 @@ using System.Collections.Generic;
 using UnityEngine;
 public enum AssassinState
 {
+    None = -1,
     Normal = 0, //正常状态
     FindPlayer = 1, //寻找主角位置
+    ReadyToDash = 2,  //准备攻击主角
+    Dash = 3,   //向主角方向冲刺
+    Down = 4,   //落地斩
 }
 public class ESpirits_Assassin : MonoBehaviour
 {
     [HideInInspector] 
     public float time;
-    public float CD;
+    public float attackCD;
+    public float readyCD;
     public float hateDistance;
     public AssassinState state;
     public Enemy enemy;
-
+    public Rigidbody rb;
+    [HideInInspector]
+    public float distance;
+    public DashEffect dashEffect;
+    public float moveSpeed;
+    public float offset;
+    [HideInInspector]
+    public Vector3 targetDir;
+    public float dashTime;
     private void Update()
     {
         switch (state)
         {
             case AssassinState.Normal:
                 time += Time.deltaTime;
-                if (time > CD)
+                if (time > attackCD)
                 {
                     enemy.isSpiritsAttack = true;
+                    time = 0;
                     state = AssassinState.FindPlayer;
+                    ChosePlayer();
+                    enemy.searchState = SearchState.InSearchScope;
+                    enemy.ChangeState(CharacterState.Run);
                 }
                 break;
             case AssassinState.FindPlayer:
-                float distance0 = Mathf.Abs(PlayersInput.instance[0].transform.position.x
-                    - transform.position.x);
-                float distance1 = Mathf.Abs(PlayersInput.instance[1].transform.position.x
-                    - transform.position.x);
-                if (distance0<=distance1)
+                ChosePlayer();
+                if (distance <= hateDistance)
                 {
-                    enemy.targetCharacter = PlayersInput.instance[0];
+                    state = AssassinState.ReadyToDash;
+                    enemy.ChangeState(CharacterState.Rush);
+                    rb.velocity = Vector3.zero;
+                    enemy.ani.Play("hitted", 0, 0);
+                    enemy.aniCollider.Play("Hurt", 0, 0);
+
                 }
-                else
+                break;
+            case AssassinState.ReadyToDash:
+                time += Time.deltaTime;
+                if (time >= readyCD)
                 {
-                    enemy.targetCharacter = PlayersInput.instance[1];
+                    state = AssassinState.Dash;
+                    dashEffect.isDash = true;
+                    dashEffect.isDashAttack = true;
+                    targetDir =
+                        (enemy.targetCharacter.transform.position - transform.position).normalized;
+                    enemy.ani.Play("attack_summon", 0, 0);
+                    time = 0;
+                }
+                break;
+            case AssassinState.Dash:
+                time += Time.deltaTime;
+                Dash();
+                if (time >= dashTime)
+                {
+                    rb.velocity = Vector3.zero;
+                    dashEffect.isDashAttack = false;
+                    time = 0;
+                    state = AssassinState.Normal;
+                    enemy.isSpiritsAttack = false;
+                    enemy.searchState = SearchState.NoTarget;
+                    enemy.ChangeState(CharacterState.Idle);
+
                 }
-                enemy.ChangeState(CharacterState.Run);
                 break;
         }
        
     }
+    public void ChosePlayer()
+    {
+        float distance0 = 1000;
+        float distance1 = 1000;
+        if (PlayersInput.instance[0])
+        {
+            distance0 = Mathf.Abs(PlayersInput.instance[0].transform.position.x
+                - transform.position.x);
+        }
+        if (PlayersInput.instance[1])
+        {
+            distance1 = Mathf.Abs(PlayersInput.instance[1].transform.position.x
+                - transform.position.x);
+        }
+        if (distance0 <= distance1)
+        {
+            enemy.targetCharacter = PlayersInput.instance[0];
+            distance = distance0;
+           
+        }
+        else
+        {
+            enemy.targetCharacter = PlayersInput.instance[1];
+            distance = distance1;
+        }
+    }
+    private void Dash()
+    {
+        if (targetDir.x < 0)
+        {
+            dashEffect.offset = offset;
+        }
+        else
+        {
+            dashEffect.offset = -offset;
+        }
+        rb.velocity = targetDir * moveSpeed;
+    }
 }

+ 0 - 4
ActionTowerDefense/Assets/Scripts/Spirits/Spirits_Dash.cs

@@ -14,8 +14,6 @@ public class Spirits_Dash : MonoBehaviour
     public GameObject dashAttackEffect;
     public float offset;
     public DashEffect dashEffect;
-    public Vector3 dir;
-    public float force;
     private void Update()
     {
         if (isDash)
@@ -47,13 +45,11 @@ public class Spirits_Dash : MonoBehaviour
         {
             rb.velocity = Vector3.right * moveSpeed;
             dashEffect.offset = offset;
-            dashEffect.force = new Vector3(dir.x *force,dir.y,0);
         }
         if (demonic.bodyTrans.localScale.x > 0)
         {
             rb.velocity = Vector3.left * moveSpeed;
             dashEffect.offset = -offset;
-            dashEffect.force = new Vector3(dir.x * -force, dir.y, 0);
         }
     }
 }