- Home /
Question by
Ver_lex · Jan 28, 2021 at 02:10 AM ·
scripting problemscript errorscripterror
A technical issue,A Technical issue
i ran a simple mouse rotation script which worked fine , and for some reason it doesn't work anymore. Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerRotation : MonoBehaviour
{
public enum MouseMode
{MouseX = 0
,MouseY = 1
,MouseXandY = 3
}
public MouseMode Mod = MouseMode.MouseXandY ;
public float SensitivityHor = 40.0f;
public float SensitivityVert = 40.0f;
private float _RotationX = 0;
public float Minimum = -70.0f;
public float Maximum = 70.0f;
void Start()
{
Rigidbody body = GetComponent<Rigidbody>();
if(body != null)
{
body.freezeRotation = true;
}
}
void Update() {
if(Mod == MouseMode.MouseX)
{
//Horizontal Rotaion (MouseX)
transform.Rotate(0 ,Input.GetAxis("Mouse X") * SensitivityHor, 0);
}
else if (Mod == MouseMode.MouseY)
{
//Vertical Rotation (MouseY)
_RotationX -= Input.GetAxis("Mouse y") * SensitivityVert;
_RotationX = Mathf.Clamp(_RotationX, Minimum,Maximum);
float RotationY = transform.localEulerAngles.y;
transform.localEulerAngles = new Vector3(_RotationX, RotationY, 0);
}
else
{
//Horizontal and Vertical Rotation (MouseXandY)
_RotationX -= Input.GetAxis("Mouse Y") * SensitivityVert;
_RotationX = Mathf.Clamp(_RotationX, Minimum, Maximum);
float Delta = Input.GetAxis("Mouse X") * SensitivityHor;
float RotationY = transform.localEulerAngles.y + Delta;
transform.localEulerAngles = new Vector3(_RotationX, RotationY, 0);
}
}
}
The problem is with the else block. i know i could be more concise but i decided to share the whole code just in case also please correct me if there is any other kind of mistakes or tips (I am a beginner).
Comment