Ver Fonte

修复跳跃的时候取消重力的问题

zhengchen há 1 ano atrás
pai
commit
e5499ae04d

+ 13 - 27
Assets/Scripts/Comp/CockActionComp.cs

@@ -29,6 +29,8 @@ namespace Comp
 
         private readonly WaitForSeconds _waitEverySecond = new WaitForSeconds(1f);
 
+        private Rigidbody _rigidbody;
+
         // 水平与垂直方向运动相关
 
         public int playerId;
@@ -43,6 +45,8 @@ namespace Comp
 
         private bool _createMiss = false;
 
+        public bool willBeLift = false;
+
         public ICockController CockController
         {
             get
@@ -70,6 +74,7 @@ namespace Comp
         private void Awake()
         {
             _cockMoveComp = GetComponent<CockMoveComp>();
+            _rigidbody = GetComponent<Rigidbody>();
         }
 
         private void Start()
@@ -95,33 +100,6 @@ namespace Comp
             CreateMissText();
         }
 
-        private void FixedUpdate()
-        {
-            // transform.Translate(_thrust * Time.deltaTime);
-
-            // 移动游戏对象
-            // if (GameCore.Instance.inBattleState)
-            // transform.position += _curData.GetJumpVector();
-            // if (GameCore.Instance.inBattleState)
-            // {
-            //     if (rightForward)
-            //     {
-            //         transform.position += _curData.GetMoveVector();
-            //     }
-            //     else
-            //     {
-            //         transform.position -= _curData.GetMoveVector();
-            //     }
-            // }
-
-            // if (transform.position.y < _miniY)
-            // {
-            //     var position = transform.position;
-            //     position = new Vector3(position.x, _miniY, position.z);
-            //     transform.position = position;
-            // }
-        }
-
         private void OnRun()
         {
             _cockMoveComp.MoveAndNeverStop();
@@ -147,10 +125,18 @@ namespace Comp
 
         public void OnAttackEnd()
         {
+            if (willBeLift)
+            {
+                _rigidbody.useGravity = false;
+            }
         }
 
         public void OnJumpEnd()
         {
+            if (willBeLift)
+            {
+                _rigidbody.useGravity = false;
+            }
         }
 
         public void SetHighJump(bool high)

+ 4 - 3
Assets/Scripts/Comp/MasterActionComp.cs

@@ -57,10 +57,11 @@ namespace Comp
             StartCoroutine(CockRayCast());
         }
 
-        private IEnumerator CockRayCast()
+        private IEnumerator CockRayCast() // 判断碰撞点,现在不用射线了
         {
             yield return new WaitForSeconds(1f);
-            var cockObj = GameCore.Instance.GetCockActionCompByPlayerId(playerId).gameObject;
+            var actionComp = GameCore.Instance.GetCockActionCompByPlayerId(playerId);
+            var cockObj = actionComp.gameObject;
             _cock = cockObj;
             if (playerId == GameCore.Instance.localPlayer.playerId)
                 _collisionX = _cock.transform.position.x - 1f;
@@ -69,7 +70,7 @@ namespace Comp
                 _collisionX = _cock.transform.position.x + 1f;
             }
 
-            _cock.GetComponent<Rigidbody>().useGravity = false; // 取消重力
+            actionComp.willBeLift = true;
         }
 
         private void FixedUpdate()

+ 3 - 1
ProjectSettings/ProjectSettings.asset

@@ -146,7 +146,9 @@ PlayerSettings:
     16:9: 1
     Others: 1
   bundleVersion: 1.0.3
-  preloadedAssets: []
+  preloadedAssets:
+  - {fileID: 3631518619006024534, guid: 67fdd7a6b94fc46bc8ae68e0872669b0, type: 2}
+  - {fileID: 11400000, guid: c09f357707e48432f97126356e4061fd, type: 2}
   metroInputSource: 0
   wsaTransparentSwapchain: 0
   m_HolographicPauseOnTrackingLoss: 1