I have a script that will lock the cursor and hide it in the center of the screen if I click the middle mouse button. Escape releases it and unhides it.
However if I start the game and don’t put my mouse in the center of the screen before it loads, it screws my camera angle up so it’s pointing straight down or straight up when the game loads and you have to scroll the mouse several times to get it facing forward. If I turn up the sensitivity then it gets too sensitive to aim.
So if I start the game, put my mouse position near the center of the screen, then once the game loads click my lockCursor button, it will center it and lock it every time perfectly.
But when I set it to enabled on start, it does hide the cursor and the camera does face perfectly forward, but the cursor is hidden on the bottom debug toolbar so the first mouse click will open the debug window in the middle of the screen every time. Manually hitting the middle mouse button to hide the cursor will hide it in the center of the screen from that point on, but the first click is always off the game window on the debug toolbar.
using UnityEngine;
using System.Collections;
public class LockCursor : MonoBehaviour {
private bool wasLocked = false;
void Awake() {
Screen.lockCursor = true;
guiTexture.enabled = false;
}
void DidLockCursor() {
Debug.Log("Locking cursor");
guiTexture.enabled = false;
}
void DidUnlockCursor() {
Debug.Log("Unlocking cursor");
guiTexture.enabled = true;
}
void Update()
{
if (Input.GetKeyDown("escape")) {
Screen.lockCursor = false;
} else if (Input.GetMouseButtonDown(2) Screen.lockCursor != true) {
Screen.lockCursor = true;
}
else {
}
}
}
Also if anyone has a simple line of code I can add to my camera scripts to reset their position to face forward that would be amazing. I think it’s simple with quaternion.identity? Any example of a OnButtonDown(“ResetCamera”) {
cam1.rotation.? = something something (something, something, quaternion.identity);
}
My cameras use a modified “MouseCameraControl”, “SmoothLookAt” and I haven’t been able to limit their view by adding a MouseLook script…not sure how to set bounds…
The MouseCameraControl I modified to move the mouse Y direction by getting raw input from mouse Y. Then the Smooth Look At moves the character left or right based on the Mouse X input.
Those are my camera questions. Thanks a lot.