Skip to content

Instantly share code, notes, and snippets.

@tubakihimeLoveHate
Last active December 10, 2020 18:14
Show Gist options
  • Save tubakihimeLoveHate/cee3a5249862de6ecdec4929980c30b8 to your computer and use it in GitHub Desktop.
Save tubakihimeLoveHate/cee3a5249862de6ecdec4929980c30b8 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VerticalOnlyCamera : MonoBehaviour
{
// This Camera move only verticle.
// So camera transform in player children.
// このカメラは縦の視点移動のみです。利用する場合はこのクラスをアタッチするカメラをプレイヤーの子にしてください。
private Vector3 angle;
[SerializeField]
private float sensitivityY;
void Start()
{
angle = transform.eulerAngles;
//Lock Cursor
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void LateUpdate()
{
angle = transform.eulerAngles;
if (Input.GetKey(KeyCode.Backspace)) UnityEditor.EditorApplication.isPlaying = false;
if (Input.GetKey(KeyCode.E))
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
float vertical;
vertical = Input.GetAxis("Mouse Y") * sensitivityY;
angle.x -= vertical * Time.deltaTime;
transform.eulerAngles = angle;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment