Jelajahi Sumber

更新脚本

lvjincheng 4 tahun lalu
induk
melakukan
4e88392977

+ 3 - 3
Assets/BowArrow/Scripts/Game/Arrow.cs

@@ -54,8 +54,8 @@ public class Arrow : MonoBehaviour
         Billboard.ins?.ShowSpeed();
 
         if (absoluteRay.transform) {
-            TargetBody targetBody = absoluteRay.transform.GetComponent<TargetBody>();
-            rayHitTargetBody = targetBody??null;
+            //记录射线有没有击中靶子
+            rayHitTargetBody = absoluteRay.transform.GetComponent<TargetBody>();
             //把瞄准点画成红圈,渲染在靶子上
             if (rayHitTargetBody) {
                 Transform redCircle = rayHitTargetBody.transform.Find("RedCircle");
@@ -136,7 +136,7 @@ public class Arrow : MonoBehaviour
     }
 
     /**发射角有无解 */
-    [NonSerialized] public bool hasParabolaAngle = false;
+    bool hasParabolaAngle = false;
     /**发射角弧度解 */
     float parabolaAngleInRadian = 0;
     /**

+ 1 - 1
Assets/BowArrow/Scripts/Game/BowCamera.cs

@@ -84,7 +84,7 @@ public class BowCamera : MonoBehaviour
                 }
             } else {
                 //镜头看向九轴姿态虚拟节点
-                this.transform.LookAt(GameObject.Find("CameraToLook/Point").transform);
+                this.transform.LookAt(CameraToLook.ins.point);
             }
         }
     }

+ 4 - 3
Assets/BowArrow/Scripts/Game/CameraToLook.cs

@@ -1,14 +1,15 @@
-using System.Collections;
-using System.Collections.Generic;
+using System;
 using UnityEngine;
 /* 弓的摄像机总会LookAt该节点的Point子节点
 九轴数据是直接应用到该节点的(特意分离而不直接应用到弓的摄像机) 是为了避免z轴旋转 
 */
 public class CameraToLook : MonoBehaviour
 {
+    [NonSerialized] public Transform point;
     public static CameraToLook ins;
-    void Start()
+    void Awake()
     {
         ins = this;
+        point = transform.Find("Point");
     }
 }

+ 4 - 4
Assets/BowArrow/Scripts/Manager/GameMgr.cs

@@ -10,7 +10,7 @@ public class GameMgr : MonoBehaviour
     public static bool debugInEditor = false;
     public static int gameType = 0;
     public GameMode gameMode;
-    public bool gameOver = false;
+    [System.NonSerialized] public bool gameOver = false;
     public static GameMgr ins;
 
     void Awake() 
@@ -179,7 +179,7 @@ public class GameModeTest : GameMode {
         //记录可射击的靶子
         if (SceneManager.GetActiveScene().name == "Game") {
             TargetBody targetBody = GameObject.Find("GameArea/TargetObject/TargetBody").GetComponent<TargetBody>();
-            GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(targetBody);
+            GameObject.FindObjectOfType<ArmBow>().validTargets.Add(targetBody);
         }
     }
     public override void HitTarget(float score) {
@@ -201,7 +201,7 @@ public class TimeLimitGameMode : GameMode {
     public TimeLimitGameMode(GameMgr gameMgr) : base(gameMgr) {
         //记录可射击的靶子
         targetBody = GameObject.Find("GameArea/TargetObject/TargetBody").GetComponent<TargetBody>();
-        GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(targetBody);
+        GameObject.FindObjectOfType<ArmBow>().validTargets.Add(targetBody);
         //添加游戏界面
         GameObject view = Resources.Load<GameObject>("Prefabs/Views/TimeLimitGameView");
         GameObject.Instantiate(view);
@@ -304,7 +304,7 @@ public class PKGameMode : GameMode {
         currentPlayerIndex = appearPlayerIndexes.Dequeue();
         //记录可射击的靶子
         targetBody = GameObject.Find("GameArea/TargetObject/TargetBody").GetComponent<TargetBody>();
-        GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(targetBody);
+        GameObject.FindObjectOfType<ArmBow>().validTargets.Add(targetBody);
         targetBody.SetDistance(targetDistancesOnRound[round - 1]);
         //添加游戏界面
         GameObject view = Resources.Load<GameObject>("Prefabs/Views/PKGameView");