- Home /
Centering mouse when not used
Hello there Unity coders,
I have a for me simple looking question, although I can't figure it out myself.
I am making a game and i want the mouse the be set back to the center after a period of time when the player hasnt touched it. I am controlling my character turning with the mouse and if I move my mouse a tiny bid my animation allready blends into turning, this is what I want but when I haven't touched the mouse for like 3 seconds, it should get centered. I know that for centering you could use:
Screen.lockCursor = true;
Screen.lockCursor = false;
But I can't seem to figure out how to time it. This is the script that I am using to check if the mouse has been moved, its in C#.
using UnityEngine; using System.Collections;
public class MouseCentering : MonoBehaviour {
public bool MouseMoved;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetAxis("Mouse X")<0){
}
if(Input.GetAxis("Mouse X")>0){
}
if(Input.GetAxis("Mouse Y")<0){
}
if(Input.GetAxis("Mouse Y")>0){
}
}
}
If someone could give me the other things that I need to get my script finished, or send me a completly new JavaScript, I would be very VERY happy.
Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220613121957im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Locking cursor/mouse on an object 1 Answer
Locking the mouse cursor without it centering after unlocking it? 0 Answers
how do i lock the mouse at center and lock it 1 Answer
Mouse Lock 1 Answer
Mouse lock to target 0 Answers