Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
// Public variables
public float MouseSensivity;
public bool RotateX;
public bool RotateY;
// Private variables
private Transform PlayerBody;
private float MouseX;
private float MouseY;
// Start is called before the first frame update
void Start()
{
PlayerBody = this.transform;
}
// Update is called once per frame
void Update()
{
if(RotateX == true)
{
MouseX = Input.GetAxis("Mouse X") * Time.deltaTime;
PlayerBody.Rotate(Vector3.up * MouseSensivity * MouseX);
}
if(RotateY == true)
{
MouseY = Input.GetAxis("Mouse Y") * Time.deltaTime;
PlayerBody.Rotate(Vector3.left * MouseSensivity * MouseY);
}
}
}