using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DescendTheWell : MonoBehaviour
{
//目標VR相機父物體
public Transform player;
//目標位置(相機被限制在這裏)
public static Transform target;
public Transform mainCamera;
public bool isNoy;//Y軸不跟隨
public static DescendTheWell I;
public bool IsPlay;
private bool isRot;
private void Awake()
{
I = GetComponent<DescendTheWell>();
}
private void Update()
{
if (mainCamera==null) {
mainCamera = Camera.main.transform;
}
if (IsPlay) {
if (isNoy)
{
Vector3 pos = target.position + ( player.position - mainCamera.position );
player.position = new Vector3(pos.x, player.position.y, pos.z); ;
}
else
{
player.position = target.position + ( player.position - mainCamera.position );
}
if (isRot)
{
SetRotation();
}
}
}
public void Play(Transform _target) {
target = _target;
IsPlay = true;
SetRotation();
}
public void Stop() {
IsPlay = false;
}
private void SetRotation()
{
Vector3 rot = target.eulerAngles + ( player.eulerAngles - mainCamera.eulerAngles );
player.eulerAngles = new Vector3(0, rot.y, 0);
}
}