Browse Source

修复胖子死了站在上面不会下落bug

LAPTOP-OM1V99U2\永远de小亡灵 1 năm trước cách đây
mục cha
commit
5627085be9

+ 18 - 2
ActionTowerDefense/Assets/Resources/Prefab/Demonic_Giant.prefab

@@ -170,9 +170,10 @@ GameObject:
   - component: {fileID: 3410108659653096532}
   - component: {fileID: 3051270209667538022}
   - component: {fileID: 6236498711544088984}
+  - component: {fileID: 5985338664562251832}
   m_Layer: 13
   m_Name: Platform
-  m_TagString: Plane
+  m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
@@ -250,11 +251,25 @@ BoxCollider:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 2605737647177614769}
   m_Material: {fileID: 0}
-  m_IsTrigger: 0
+  m_IsTrigger: 1
   m_Enabled: 1
   serializedVersion: 2
   m_Size: {x: 1, y: 10, z: 20}
   m_Center: {x: 0, y: -5, z: 0}
+--- !u!114 &5985338664562251832
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 2605737647177614769}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: e11ee644ccfe95b4ca9ed53d307729d5, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  rb: {fileID: 5440846222648032765}
+  feet: []
 --- !u!1 &4480734502875862885
 GameObject:
   m_ObjectHideFlags: 0
@@ -649,6 +664,7 @@ MonoBehaviour:
   soulStartSpeed: 1
   isInvisible: 0
   invisibleTime: 0
+  velocityAddition: {x: 0, y: 0, z: 0}
   easyToGetHit: 0.2
   player: {fileID: 0}
   id: 0

+ 23 - 9
ActionTowerDefense/Assets/Scripts/Foot.cs

@@ -28,23 +28,37 @@ public class Foot : MonoBehaviour
             {
                 rb.useGravity = true;
                 haveGravity = true;
+                rb.GetComponent<MoveCharacter>().velocityAddition = Vector3.zero;
             }
         }
         else
         {
-            if (haveGravity && rb.velocity.y<0)
+            if (haveGravity)
             {
-                foreach (GameObject i in trigGroundList)
+                if (rb.velocity.y < 0)
                 {
-                    if (i.layer == 13)
+                    foreach (GameObject i in trigGroundList)
                     {
-                        rb.useGravity = false;
-                        rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
-                        haveGravity = false;
-                        rb.transform.position = new Vector3
-                            (rb.transform.position.x, i.transform.position.y, rb.transform.position.z);
-                        break;
+                        if (i.layer == 13)
+                        {
+                            rb.useGravity = false;
+                            rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z);
+                            haveGravity = false;
+                            rb.transform.position = new Vector3
+                                (rb.transform.position.x, i.transform.position.y, rb.transform.position.z);
+                            break;
+                        }
                     }
+
+                }
+
+            }
+            else
+            {
+                Platform platform = trigGroundList[0].GetComponent<Platform>();
+                if (platform != null)
+                {
+                    rb.GetComponent<MoveCharacter>().velocityAddition = rb.velocity;
                 }
             }
 

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

@@ -88,6 +88,7 @@ public class MoveCharacter : Character
     public float soulStartSpeed = 1f;
     public bool isInvisible;
     public float invisibleTime;
+    public Vector3 velocityAddition;
 
     private void Awake()
     {

+ 45 - 0
ActionTowerDefense/Assets/Scripts/Platform.cs

@@ -0,0 +1,45 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Platform : MonoBehaviour
+{
+    public Rigidbody rb;
+    public List<Foot> feet = new List<Foot>();
+
+    private void OnTriggerEnter(Collider other)
+    {
+        
+        Foot foot = other.GetComponent<Foot>();
+        if (foot != null)
+        {
+            foot.trigGroundList.Add(gameObject);
+            feet.Add(foot);
+        }
+    }
+    private void OnTriggerExit(Collider other)
+    {
+        Foot foot = other.GetComponent<Foot>();
+        if(foot != null)
+        {
+            if(foot.trigGroundList.Exists(i =>i == gameObject))
+            {
+                foot.trigGroundList.Remove(gameObject);
+            }
+            if(feet.Exists(i => i == foot))
+            {
+                feet.Remove(foot);
+            }
+        }
+    }
+    private void OnDisable()
+    {
+        foreach(Foot i in feet)
+        {
+            if(i.trigGroundList.Exists(a => a == gameObject))
+            {
+                i.trigGroundList.Remove(gameObject);
+            }
+        }
+    }
+}

+ 11 - 0
ActionTowerDefense/Assets/Scripts/Platform.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e11ee644ccfe95b4ca9ed53d307729d5
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: