Ver código fonte

双人同屏

LAPTOP-OM1V99U2\永远de小亡灵 1 ano atrás
pai
commit
a011c9a6f7
1 arquivos alterados com 21 adições e 4 exclusões
  1. 21 4
      ActionTowerDefense/Assets/Scripts/CameraController.cs

+ 21 - 4
ActionTowerDefense/Assets/Scripts/CameraController.cs

@@ -4,7 +4,6 @@ using UnityEngine;
 
 public class CameraController : MonoBehaviour
 {
-    public PlayerController player;
     public float offsetX = 5, offsetY = 2, offsetZ = -10;
     public float lerpValue = 0.02f;
 
@@ -13,15 +12,33 @@ public class CameraController : MonoBehaviour
 
     private void FixedUpdate()
     {
-        if (player.bodyTrans.localScale.x > 0)
+        if (PlayersInput.instance[0] == null)
+        {
+            targetPos = Vector3.zero + new Vector3(0, offsetY, offsetZ);
+        }
+        else if(PlayersInput.instance[1] == null)
         {
-            targetPos = player.transform.position + new Vector3 (-offsetX, offsetY, offsetZ);
+            targetPos = CameraTargetMove(PlayersInput.instance[0]);
         }
         else
         {
-            targetPos = player.transform.position + new Vector3(offsetX, offsetY, offsetZ);
+            targetPos = Vector3.Lerp(PlayersInput.instance[0].transform.position,
+                PlayersInput.instance[1].transform.position, 0.5f) + new Vector3(0,offsetY,offsetZ);
         }
 
         transform.position = Vector3.Lerp(transform.position, targetPos, lerpValue * Time.deltaTime);
     }
+
+    Vector3 CameraTargetMove(PlayerController player)
+    {
+        if (player.bodyTrans.localScale.x > 0)
+        {
+            targetPos = player.transform.position + new Vector3(-offsetX, offsetY, offsetZ);
+        }
+        else
+        {
+            targetPos = player.transform.position + new Vector3(offsetX, offsetY, offsetZ);
+        }
+        return targetPos;
+    }
 }