Răsfoiți Sursa

弓的相机脚本更新

lvjincheng 4 ani în urmă
părinte
comite
700f616f5a
1 a modificat fișierele cu 29 adăugiri și 24 ștergeri
  1. 29 24
      Assets/BowArrow/Scripts/Game/BowCamera.cs

+ 29 - 24
Assets/BowArrow/Scripts/Game/BowCamera.cs

@@ -8,12 +8,17 @@ public class BowCamera : MonoBehaviour
     Camera cameraComp;
     Camera cameraComp;
     //本地欧拉角记录值
     //本地欧拉角记录值
     Vector3 localEulerAngles;
     Vector3 localEulerAngles;
+    //控制的手臂弓
+    ArmBow armBow;
+    //触摸模式开关
+    bool isTouchMode = true;
     public static BowCamera ins;
     public static BowCamera ins;
 
 
     void Awake() {
     void Awake() {
         ins = this;
         ins = this;
         cameraComp = GetComponent<Camera>();
         cameraComp = GetComponent<Camera>();
         localEulerAngles = transform.localEulerAngles;
         localEulerAngles = transform.localEulerAngles;
+        armBow = GetComponentInChildren<ArmBow>();
     }
     }
 
 
     void Update()
     void Update()
@@ -38,39 +43,39 @@ public class BowCamera : MonoBehaviour
                 return;
                 return;
             }
             }
             if (Input.GetMouseButtonDown(0)) {
             if (Input.GetMouseButtonDown(0)) {
-                ArmBow.ins.mouseDown();
+                armBow.mouseDown();
             }
             }
             else if (Input.GetMouseButtonUp(0)) {
             else if (Input.GetMouseButtonUp(0)) {
-                ArmBow.ins.mouseUp();
+                armBow.mouseUp();
             }
             }
         } else {
         } else {
-            //镜头看向九轴姿态虚拟节点
-            this.transform.LookAt(GameObject.Find("CameraToLook/Point").transform);
-
-            //触摸控制镜头和拉弓射箭
-            #region 
-            if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Moved)
-            {
-                if (!EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId))
+            if (isTouchMode) {
+                //触摸控制镜头和拉弓射箭
+                if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Moved)
                 {
                 {
-                    this.localEulerAngles.x = Mathf.Clamp(this.localEulerAngles.x - Input.touches[0].deltaPosition.y * Time.deltaTime * 5, -36, 36);
-                    this.localEulerAngles.y = Mathf.Clamp(this.localEulerAngles.y + Input.touches[0].deltaPosition.x * Time.deltaTime * 5, -180, 180);   
-                    this.transform.localEulerAngles = this.localEulerAngles; 
+                    if (!EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId))
+                    {
+                        this.localEulerAngles.x = Mathf.Clamp(this.localEulerAngles.x - Input.touches[0].deltaPosition.y * Time.deltaTime * 5, -36, 36);
+                        this.localEulerAngles.y = Mathf.Clamp(this.localEulerAngles.y + Input.touches[0].deltaPosition.x * Time.deltaTime * 5, -180, 180);   
+                        this.transform.localEulerAngles = this.localEulerAngles; 
+                    }
                 }
                 }
-            }
-            if (Input.touches.Length > 0)
-            {
-                foreach (Touch touch in Input.touches)
+                if (Input.touches.Length > 0)
+                {
+                    foreach (Touch touch in Input.touches)
+                    {
+                        if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) return;
+                    }
+                    armBow.mouseDown();
+                } 
+                if (Input.touches.Length == 0)
                 {
                 {
-                    if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) return;
+                    armBow.mouseUp();
                 }
                 }
-                ArmBow.ins.mouseDown();
-            } 
-            if (Input.touches.Length == 0)
-            {
-                ArmBow.ins.mouseUp();
+            } else {
+                //镜头看向九轴姿态虚拟节点
+                this.transform.LookAt(GameObject.Find("CameraToLook/Point").transform);
             }
             }
-            #endregion
         }
         }
     }
     }