'Why is my Unity Camera getting messed up whenever I add a lookaround code in c#
My unity camera is parented with the gun so the gun is supposed to be on the side but whenever I add my lookaround script my unity camera goes to the center of the gun not the side.
Lookaround script:
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public float mouseSensitivity = 100f;
public Transform playerBody;
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);
playerBody.Rotate(Vector3.up * mouseX);
}
}
For the gun I just parented the camera with it but now whenever I run the game it automatically puts my camera in the middle of the gun. By the way my code language is C#.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
