Browse Source

Update ChangeRotation_SyncGameObjectRotation.cs (#295)

修复View层ChangeRotation_SyncGameObjectRotation报错,逻辑层修改了Rotation,View层这时候可能还没创建好,需要判断一下
sunset 4 years ago
parent
commit
de13d3acac

+ 8 - 3
Unity/Codes/HotfixView/Demo/Unit/ChangeRotation_SyncGameObjectRotation.cs

@@ -1,4 +1,4 @@
-using UnityEngine;
+using UnityEngine;
 
 namespace ET
 {
@@ -6,9 +6,14 @@ namespace ET
     {
         protected override async ETTask Run(EventType.ChangeRotation args)
         {
-            Transform transform = args.Unit.GetComponent<GameObjectComponent>().GameObject.transform;
+            GameObjectComponent gameObjectComponent = args.Unit.GetComponent<GameObjectComponent>();
+            if (gameObjectComponent == null)
+            {
+                return;
+            }
+            Transform transform = gameObjectComponent.GameObject.transform;
             transform.rotation = args.Unit.Rotation;
             await ETTask.CompletedTask;
         }
     }
-}
+}