Can someone help with the script i wanted when i press “escape” it shows cursor (locks sceen)but when i press “fire1” it DOESN’T unlock the cursor (I just wanted my mouse to not show while im palying only when i prees “esape”) thanx… ![]()
sorry i forgot script
function Start ()
{
// Start out in paused mode in web player
if (Application.platform == RuntimePlatform.OSXWebPlayer ||
Application.platform == RuntimePlatform.WindowsWebPlayer)
{
SetPause(true);
}
else
{
SetPause(false);
Screen.lockCursor = true;
}
}
function OnApplicationQuit ()
{
Time.timeScale = 1;
}
function SetPause (pause : boolean)
{
Input.ResetInputAxes();
var gos : Object[] = FindObjectsOfType(GameObject);
for (var go : GameObject in gos)
go.SendMessage("DidPause", pause, SendMessageOptions.DontRequireReceiver);
transform.position = Vector3.zero;
if (pause)
{
Time.timeScale = 0;
transform.position = Vector3 (.5, .5, 0);
guiText.anchor = TextAnchor.MiddleCenter;
}
else
{
guiText.anchor = TextAnchor.UpperLeft;
transform.position = Vector3(0, 1, 0);
Time.timeScale = 1;
}
}
function DidPause (pause : boolean)
{
if (pause)
{
// Show the button again
guiText.enabled = true;
guiText.text = "Click to start playing";
}
else
{
// Disable the button
guiText.enabled = true;
guiText.text = "Escape to show the cursor";
}
}
function OnMouseDown ()
{
// Lock the cursor
Screen.lockCursor = true;
}
private var wasLocked = false;
function Update ()
{
if (Input.GetMouseButton(0))
Screen.lockCursor = true;
// Did we lose cursor locking?
// eg. because the user pressed escape
// or because he switched to another application
// or because some script set Screen.lockCursor = false;
if (!Screen.lockCursor wasLocked)
{
wasLocked = false;
SetPause(true);
}
// Did we gain cursor locking?
else if (Screen.lockCursor !wasLocked)
{
wasLocked = true;
SetPause(false);
}
}
Still nobody?
Guys does anybody know script to hide cursor?
Did you read the caveats to Screen.lockCursor? Is this happening in the web player? If so, it’s expected that the cursor won’t lock when you press escape (or in another of a number of circumstances).
You probably haven’t received any answers yet because 1) The subject of your post isn’t at all descriptive (try something like “How do I hide the cursor?”). People probably think this one of the many threads asking how to make a gun shoot a projectile. 2) You only posted it an hour ago. It’s impolite to bump your question twice less than an hour after you posted it.
Thanx for the script but now i want my cursor to hide while i’m playing , i wanted only to show cursor when i press escape and that works but now this is problem,Can someone help please ![]()
The way I do this is the following:
When I press escape while the screen is locked, unlock the screen.
When I press escape while the screen is unlocked, lock the screen.
I only wanted when i prees escape it unlocks sceen but if i click or press esape again it doesn’t lock the sceen cause i have problem while i’m shooting a have an AIM (gui point) and my problem is cursor i see it it really bugs me i only want to hide it while i’m playing and when i press escape it shows cursor … help ???
Why not just lock the screen on start? Then unlock it later if you press escape.
Can you give me a script or add it to this
// Called when the cursor is actually being locked
function DidLockCursor () {
Debug.Log("Locking cursor");
// Disable the button
guiTexture.enabled = false;
}
// Called when the cursor is being unlocked
// or by a script calling Screen.lockCursor = false;
function DidUnlockCursor () {
Debug.Log("Unlocking cursor");
// Show the button again
guiTexture.enabled = true;
}
function OnMouseDown () {
// Lock the cursor
Screen.lockCursor = true;
}
private var wasLocked = false;
function Update () {
// In standalone player we have to provide our own key
// input for unlocking the cursor
if (Input.GetKeyDown ("escape"))
Screen.lockCursor = false;
Screen.showCursor = false;
// Did we lose cursor locking?
// eg. because the user pressed escape
// or because he switched to another application
// or because some script set Screen.lockCursor = false;
if (!Screen.lockCursor wasLocked) {
wasLocked = false;
DidUnlockCursor();
}
// Did we gain cursor locking?
else if (Screen.lockCursor !wasLocked) {
wasLocked = true;
DidLockCursor ();
}
}
No, I’m not going to write your script for you. And I implore everyone else to not write his script for him either.
Add a Start() function, inside of which you lock the screen (with Screen.lockCursor = true).
This is such a simple script. You need to be able to understand what this script does if you want to use Unity.
I’ve done that befour and what happends my cursor is flashing…Can you help?
If your cursor was flashing, you were probably doing it in the Update() function, not the Start() function.
No i was doing it in Start function but i was doing that while i was in unity program but now when i turn it into game the cursor doesnt show thanx for help but can you help me with this just this please i want when i pres escape it shows cursor please… ![]()
Okay, so when you press escape, set Screen.lockCursor = false.
I puttint in Start() function and itdidn’t show cursor when i pressed escape do you know how to help or it doesn’t mater…Thax for everything… ![]()
You don’t put input-handling code in Start(). Start() is only called once, when the game starts. You put your input-handling code in Update() because update gets called once before every frame.
I don’t know it doesn’t work it doesn’t matter do you know script how can i select my gui buttons by pressing buttons up,down…?
Sorry to bother ![]()
How can you select your gui buttons by pressing keyboard buttons? This seems like a different problem. What are you talking about?