I am trying to keep the cursor in the centre of the screen* / reset it to the center. i know screen.lockCursor works but as your probably aware its no longer used in unity 5. For some reason CursorLockMode.Locked is not locking the cursor and neither is .Confined, im not exactly sure how else to do this. Any help on this appreciated.
(*or where ever it was originally clicked if possible)
Code:
using UnityEngine;
using System.Collections;
public class Rotate : MonoBehaviour {
public bool rotate = true;
public float midx = Screen.width/2;
CursorLockMode mode;
private static int buttonHeight = Screen.height/24;
private static int buttonWidth = Screen.width/12;
int blendShapeCount;
SkinnedMeshRenderer skinnedMeshRenderer;
Mesh skinnedMesh;
float blendOne = 0f;
float blendSpeed = 0.1f;
public bool TF1;
int Element0;
void SetCursorState ()
{
Cursor.lockState = mode;
Cursor.visible = (CursorLockMode.Locked != mode);
}
void Awake ()
{
skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer> ();
}
void Start() {
}
void Update() {
if (rotate == true) {
transform.RotateAround (Vector3.zero, Vector3.up, 20 * Time.deltaTime);
}
if (Input.GetMouseButton (1)) {
if (Input.GetAxis ("Mouse X") < 0) {
transform.RotateAround (Vector3.zero, Vector3.up, 180 * Time.deltaTime);
mode = CursorLockMode.Confined;
mode = CursorLockMode.Locked;
Cursor.visible = false;
}
if (Input.GetAxis ("Mouse X") > 0) {
transform.RotateAround (Vector3.zero, Vector3.up, -180 * Time.deltaTime);
mode = CursorLockMode.Confined;
mode = CursorLockMode.Locked;
Cursor.visible = false;
}
} else {
mode = CursorLockMode.None;
Cursor.visible = true;
}
if (Element0 <= 0) {
TF1 = true;
}
if (Element0 > 100) {
TF1 = false;
}
if (TF1 == true) {
skinnedMeshRenderer.SetBlendShapeWeight (0, blendOne);
blendOne += blendSpeed;
Element0 = (int)blendOne;
} else {
skinnedMeshRenderer.SetBlendShapeWeight (0, blendOne);
blendOne -= blendSpeed;
Element0 = (int)blendOne;
}
}
void OnMouseOver() {
rotate = false;
}
void OnMouseExit() {
rotate = true;
}
}