using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraController : MonoBehaviour { public static CameraController Instance { get; set; } public float smooth; public float distToTable; public Transform tablePlane; private Vector3 posVel = Vector3.zero; private Vector3 rotVel = Vector3.zero; private Vector3 menuPosition; private Quaternion menuRotation; private bool movesOnTable; private bool movesOnMenu; void Awake() { //Manage Singleton if (Instance != null && Instance != this) Destroy(gameObject); else Instance = this; DontDestroyOnLoad(gameObject); } void Start() { menuPosition = transform.position; menuRotation = transform.rotation; } void Update() { Vector3 pos, angles; if (movesOnTable) { pos = tablePlane.position + Vector3.up * distToTable; angles = (tablePlane.rotation * Quaternion.Euler(90, 0, 90)).eulerAngles; MoveSmoothly(pos, angles); float dist = Vector3.Distance(pos, transform.position); if (dist < 0.01) { movesOnTable = false; GUIController.Instance.ShowLobby(); } } if (movesOnMenu) { pos = menuPosition; angles = menuRotation.eulerAngles; MoveSmoothly(pos, angles); float dist = Vector3.Distance(pos, transform.position); if (dist < 1) { movesOnMenu = false; GUIController.Instance.ShowMenu(); } } } private void MoveSmoothly(Vector3 pos, Vector3 angles) { transform.position = Vector3.SmoothDamp(transform.position, pos, ref posVel, smooth); transform.rotation = Quaternion.Euler(Vector3.SmoothDamp(transform.rotation.eulerAngles, angles, ref rotVel, smooth)); } public void MoveOnTable() { movesOnTable = true; movesOnMenu = false; } public void MoveOnMenu() { movesOnMenu = true; movesOnTable = false; } }