I have an object that slides left-right based on the user’s mouse position and it works perfectly. When the user pauses the game, the user looses control over the object (it’s paused… so this is as expected and as wanted). The issue the springs up is that when the user un-pauses the game, the object then snaps to wherever the user has moved the mouse while the game was paused instead of starting where its last resting place was.
I’m using the following for the code:
function Update () {
if (GlobalVariables.paused == false) {
// Captures the current mouse position -- Vector3()
var mPos = Input.mousePosition;
// DELETED CODE TO LIMIT ON X-AXIS TO SIMPLIFY SCRIPT FOR THIS QUESTION
// Converts mouse position to world coordinates
var currentPos = cam.camera.ScreenToWorldPoint(mPos);
// Moves the object to where the mouse is
transform.position = currentPos;
}
}
I tried to use:
Input.mousePosition = Vector3( x, y, z);
… but it says that it’s read-only.
Again, I basically am looking for a way to snap my the user’s mouse cursor to the location of the gameObject when un-pausing the game.
Thanks in advance as this seems like a simple task, yet I can’t seem to find this answer anywhere.