111
This commit is contained in:
51
Assets/GameRes/Main/SceneArt/VRScene/Scripts/FreeView.cs
Normal file
51
Assets/GameRes/Main/SceneArt/VRScene/Scripts/FreeView.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FreeView : MonoBehaviour
|
||||
{
|
||||
Vector3 rotDir;
|
||||
public float rotSpeed;
|
||||
float deltaTime;
|
||||
public Camera viewCam;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
deltaTime = Time.deltaTime;
|
||||
|
||||
CursuorAction();
|
||||
CameraAction();
|
||||
}
|
||||
|
||||
public void CursuorAction()
|
||||
{
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void CameraAction()
|
||||
{
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
rotDir.x += Input.GetAxis("Mouse X") * rotSpeed * deltaTime;
|
||||
rotDir.y -= Input.GetAxis("Mouse Y") * rotSpeed * deltaTime;
|
||||
rotDir.y = Mathf.Clamp(rotDir.y, -90, 90);
|
||||
viewCam.transform.localRotation = Quaternion.Euler(new Vector3(rotDir.y, 0, 0));
|
||||
transform.rotation = Quaternion.Euler(new Vector3(0, rotDir.x, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user