So i have a raycast shooting out from where my mouse is pointing, and i made a simple lock cursor script for the use of menu options later, but that script wont lock the mouse in center. Anyone know how to fix this? (Note: I have been looking in Scripting API but not found a way to script it.)
This is what i was thinking on how the script whould be like:
void Update ()
{
if (Input.GetKey(KeyCode.Escape))
Screen.lockCursor = false;
else
Screen.lockCursor = true;
//Move and lock the mouse position to center of the main camera
}
Here is my Raycasting script if needed:
void Update ()
{
if (Input.GetMouseButtonDown (0))
{
Ray rayOrigin = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hitInfo;
if(Physics.Raycast (rayOrigin, out hitInfo, distance))
{
Debug.Log ("You are casting Ray");
Debug.DrawLine (rayOrigin.direction, hitInfo.point, Color.blue);
if(hitInfo.rigidbody !=null)
{
hitInfo.rigidbody.AddForceAtPosition (rayOrigin.direction * power,hitInfo.point);
}
}