プレーヤーの視点を変更する

視点変更の機能の実装
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public float mouseSensitivity; //感度
public Transform player;
private float xRotation = 0f;
void Start()
{
// カーソルキーを非表示にする。
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; // 左右の動き
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime; // 上下の動き
// 上下運動
xRotation -= mouseY;
// 上下運動(移動できる角度)に制限を加える。
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
// 左右運動
player.Rotate(Vector3.up * mouseX);
}
}



【2019版】X_Mission(基礎/全51回)
他のコースを見る
視点変更の機能の実装
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public float mouseSensitivity; //感度
public Transform player;
private float xRotation = 0f;
void Start()
{
// カーソルキーを非表示にする。
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; // 左右の動き
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime; // 上下の動き
// 上下運動
xRotation -= mouseY;
// 上下運動(移動できる角度)に制限を加える。
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
// 左右運動
player.Rotate(Vector3.up * mouseX);
}
}



プレーヤーの視点を変更する