Эх сурвалжийг харах

【使魔】的朝向需要随着玩家的朝向改变 不同的怪物需要设置不同的移动速度(有个随机范围)

wulifu 1 жил өмнө
parent
commit
74e557ff54

+ 3 - 1
ActionTowerDefense/Assets/Resources/Prefab/Enemy_Arrow.prefab

@@ -1001,7 +1001,7 @@ MonoBehaviour:
   foot: {fileID: 8639832132450015562}
   foot: {fileID: 8639832132450015562}
   extraRiseGravity: -28.8
   extraRiseGravity: -28.8
   extraFallGravity: -14.4
   extraFallGravity: -14.4
-  maxMoveSpeed: 5
+  moveSpeed: 5
   hurtKeepTime: 0
   hurtKeepTime: 0
   totalHurtKeepTime: 0.5
   totalHurtKeepTime: 0.5
   id: 0
   id: 0
@@ -1014,6 +1014,8 @@ MonoBehaviour:
   canHitFly: 0
   canHitFly: 0
   targetCharacter: {fileID: 0}
   targetCharacter: {fileID: 0}
   attackRatio: 0
   attackRatio: 0
+  maxMoveSpeed: 2.2
+  minMoveSpeed: 1.8
 --- !u!54 &8639832132491289349
 --- !u!54 &8639832132491289349
 Rigidbody:
 Rigidbody:
   m_ObjectHideFlags: 0
   m_ObjectHideFlags: 0

+ 3 - 1
ActionTowerDefense/Assets/Resources/Prefab/Enemy_Giant.prefab

@@ -456,7 +456,7 @@ MonoBehaviour:
   foot: {fileID: 5440846222604650418}
   foot: {fileID: 5440846222604650418}
   extraRiseGravity: -28.8
   extraRiseGravity: -28.8
   extraFallGravity: -14.4
   extraFallGravity: -14.4
-  maxMoveSpeed: 1
+  moveSpeed: 5
   hurtKeepTime: 0
   hurtKeepTime: 0
   totalHurtKeepTime: 0.5
   totalHurtKeepTime: 0.5
   id: 0
   id: 0
@@ -469,6 +469,8 @@ MonoBehaviour:
   canHitFly: 0
   canHitFly: 0
   targetCharacter: {fileID: 0}
   targetCharacter: {fileID: 0}
   attackRatio: 0
   attackRatio: 0
+  maxMoveSpeed: 1.2
+  minMoveSpeed: 0.8
 --- !u!54 &5440846222648032765
 --- !u!54 &5440846222648032765
 Rigidbody:
 Rigidbody:
   m_ObjectHideFlags: 0
   m_ObjectHideFlags: 0

+ 3 - 1
ActionTowerDefense/Assets/Resources/Prefab/Enemy_Sword.prefab

@@ -251,7 +251,7 @@ MonoBehaviour:
   foot: {fileID: 2437299196663985756}
   foot: {fileID: 2437299196663985756}
   extraRiseGravity: -28.8
   extraRiseGravity: -28.8
   extraFallGravity: -14.4
   extraFallGravity: -14.4
-  maxMoveSpeed: 1.8
+  moveSpeed: 5
   hurtKeepTime: 0
   hurtKeepTime: 0
   totalHurtKeepTime: 0.5
   totalHurtKeepTime: 0.5
   id: 0
   id: 0
@@ -264,6 +264,8 @@ MonoBehaviour:
   canHitFly: 0
   canHitFly: 0
   targetCharacter: {fileID: 0}
   targetCharacter: {fileID: 0}
   attackRatio: 0
   attackRatio: 0
+  maxMoveSpeed: 2
+  minMoveSpeed: 1.6
 --- !u!54 &2437299196472462355
 --- !u!54 &2437299196472462355
 Rigidbody:
 Rigidbody:
   m_ObjectHideFlags: 0
   m_ObjectHideFlags: 0

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

@@ -123,7 +123,14 @@ public class Demonic : MoveCharacter
         switch (searchState)
         switch (searchState)
         {
         {
             case SearchState.NoTarget:
             case SearchState.NoTarget:
-                moveDir = Vector3.left;
+                if (PlayerController.instance.bodyTrans.localScale.x > 0)
+                {
+                    moveDir = Vector3.left;
+                }
+                else
+                {
+                    moveDir = Vector3.right;
+                }
                 break;
                 break;
             case SearchState.InSearchScope:
             case SearchState.InSearchScope:
                 if (targetCharacter)
                 if (targetCharacter)
@@ -237,7 +244,7 @@ public class Demonic : MoveCharacter
                 if (leftDir.x > 0.3f)
                 if (leftDir.x > 0.3f)
                 {
                 {
                     //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
                     //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
-                    rb.velocity = Vector3.right * maxMoveSpeed;
+                    rb.velocity = Vector3.right * moveSpeed;
                     //if (rb.velocity.x > maxMoveSpeed)
                     //if (rb.velocity.x > maxMoveSpeed)
                     //{
                     //{
                     //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
                     //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
@@ -250,7 +257,7 @@ public class Demonic : MoveCharacter
                 else if (leftDir.x < -0.3f)
                 else if (leftDir.x < -0.3f)
                 {
                 {
                     //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
                     //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
-                    rb.velocity = Vector3.left * maxMoveSpeed;
+                    rb.velocity = Vector3.left * moveSpeed;
                     //if (rb.velocity.x < -maxMoveSpeed)
                     //if (rb.velocity.x < -maxMoveSpeed)
                     //{
                     //{
                     //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
                     //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);

+ 4 - 2
ActionTowerDefense/Assets/Scripts/Enemy.cs

@@ -35,6 +35,7 @@ public class Enemy : MoveCharacter
 
 
     public Character targetCharacter;
     public Character targetCharacter;
     public float attackRatio;
     public float attackRatio;
+    public float maxMoveSpeed, minMoveSpeed;
 
 
     private void Awake()
     private void Awake()
     {
     {
@@ -49,6 +50,7 @@ public class Enemy : MoveCharacter
     public override void Init()
     public override void Init()
     {
     {
         base.Init();
         base.Init();
+        moveSpeed = Random.Range(minMoveSpeed, maxMoveSpeed);
         ChangeSearchState(SearchState.NoTarget);
         ChangeSearchState(SearchState.NoTarget);
     }
     }
 
 
@@ -183,7 +185,7 @@ public class Enemy : MoveCharacter
                 if (leftDir.x > 0.3f)
                 if (leftDir.x > 0.3f)
                 {
                 {
                     //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
                     //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
-                    rb.velocity = Vector3.right * maxMoveSpeed;
+                    rb.velocity = Vector3.right * moveSpeed;
                     //if (rb.velocity.x > maxMoveSpeed)
                     //if (rb.velocity.x > maxMoveSpeed)
                     //{
                     //{
                     //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
                     //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
@@ -196,7 +198,7 @@ public class Enemy : MoveCharacter
                 else if (leftDir.x < -0.3f)
                 else if (leftDir.x < -0.3f)
                 {
                 {
                     //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
                     //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
-                    rb.velocity = Vector3.left * maxMoveSpeed;
+                    rb.velocity = Vector3.left * moveSpeed;
                     //if (rb.velocity.x < -maxMoveSpeed)
                     //if (rb.velocity.x < -maxMoveSpeed)
                     //{
                     //{
                     //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
                     //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);

+ 1 - 1
ActionTowerDefense/Assets/Scripts/MoveCharacter.cs

@@ -8,7 +8,7 @@ public class MoveCharacter : Character
 
 
     public float extraRiseGravity = 0; //上升时额外重力加速度
     public float extraRiseGravity = 0; //上升时额外重力加速度
     public float extraFallGravity = -10; //下落时额外重力加速度
     public float extraFallGravity = -10; //下落时额外重力加速度
-    public float maxMoveSpeed = 5;
+    public float moveSpeed = 5;
 
 
     [HideInInspector]
     [HideInInspector]
     public float hurtKeepTime;
     public float hurtKeepTime;

+ 4 - 4
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -411,11 +411,11 @@ public class PlayerController : MoveCharacter
                 CheckTurn();
                 CheckTurn();
                 if (leftDir.x > 0.3f)
                 if (leftDir.x > 0.3f)
                 {
                 {
-                    rb.velocity = Vector3.right * maxMoveSpeed;
+                    rb.velocity = Vector3.right * moveSpeed;
                 }
                 }
                 else if (leftDir.x < -0.3f)
                 else if (leftDir.x < -0.3f)
                 {
                 {
-                    rb.velocity = Vector3.left * maxMoveSpeed;
+                    rb.velocity = Vector3.left * moveSpeed;
                 }
                 }
                 break;
                 break;
             case CharacterState.Rise:
             case CharacterState.Rise:
@@ -715,11 +715,11 @@ public class PlayerController : MoveCharacter
         CheckTurn();
         CheckTurn();
         if (leftDir.x > 0.3f)
         if (leftDir.x > 0.3f)
         {
         {
-            rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
+            rb.velocity = new Vector3(moveSpeed, rb.velocity.y, rb.velocity.z);
         }
         }
         else if (leftDir.x < -0.3f)
         else if (leftDir.x < -0.3f)
         {
         {
-            rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
+            rb.velocity = new Vector3(-moveSpeed, rb.velocity.y, rb.velocity.z);
         }
         }
         else
         else
         {
         {