| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CameraController : MonoBehaviour
- {
- public float offsetX = 6, offsetY = 3, offsetZ = -16;
- public float lerpValue = 3.5f;
- [HideInInspector]
- public Vector3 targetPos;
- public Camera mainCamera;
- public GameObject cameras;
- public Camera leftCamera;
- public Camera rightCamera;
- private void FixedUpdate()
- {
- if (PlayersInput.instance[0] == null)
- {
- targetPos = Vector3.zero + new Vector3(0, offsetY, offsetZ);
- }
- else if(PlayersInput.instance[1] == null)
- {
- targetPos = CameraTargetMove(PlayersInput.instance[0]);
- }
- else
- {
- 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;
- }
- }
|