using System.Collections; using System.Collections.Generic; using UnityEngine; public class Island : MonoBehaviour { public static Island Instance { get; set; } public float rotateSpeed; public float smooth; public Vector3 leftPosition; private float yRot; private Vector3 gameRotation = Vector3.zero; private Vector3 gameRotVel; private Vector3 moveVel; private Vector3 rightPosition; private Vector3 side; private bool rotatesToZero; private bool rotates = true; void Awake() { //Manage Singleton if (Instance != null && Instance != this) Destroy(gameObject); else Instance = this; DontDestroyOnLoad(gameObject); } void Start() { rightPosition = transform.position; side = rightPosition; } void Update() { if (rotatesToZero) { Vector3 eulers = Vector3.SmoothDamp(transform.rotation.eulerAngles, gameRotation, ref gameRotVel, smooth); transform.rotation = Quaternion.Euler(eulers); float diff = Quaternion.Angle(transform.rotation, Quaternion.Euler(gameRotation)); if (diff < 5) CameraController.Instance.MoveOnTable(); } if (rotates) { yRot += rotateSpeed; transform.rotation = Quaternion.AngleAxis(yRot, Vector3.up); } MoveToSide(); } private void MoveToSide() { transform.position = Vector3.SmoothDamp(transform.position, side, ref moveVel, smooth * 0.5f); } public void MoveLeft() { side = leftPosition; } public void MoveRight() { side = rightPosition; } public void RotateToZero() { rotatesToZero = true; rotates = false; } public void FreeRotate() { rotates = true; rotatesToZero = false; } }