- Home /
How can i disable the Mouse Cursor?
This is what I'm trying to actually ask.
You know when your Internet browser is buffering and your waiting for that little blue spinny logo to go away.
That's what I kind of want my game to do. Disable the clicking ability as long as this certain thing is functioning. Then when it's done functioning clicking will be available.
I'm kind of thinking about going for a true and false statement.
I searched it up, but I didn't find anything.
Can someone please help me out with this?
Answer by Xeong-Hu · Mar 26, 2014 at 02:42 AM
After 5 hours of struggling with this thing and eating dinner... I finally found out what my problem was.
I just had everything misplaced.
My new Code.
private var showButton = false;
private var pos : Vector2;
private var hit : RaycastHit;
var Occupied1 : GameObject;
var Occupied2 : GameObject;
var Occupied3 : GameObject;
var Occupied4 : GameObject;
var Occupied5 : GameObject;
var Clicked = false;
var Zone1 : float = 3.546595;
var Zone2 : float = 1.466332;
var Zone3 : float = -0.5914766;
var Zone4 : float = -2.645551;
var Zone5 : float = 3.546595;
var jeq : MonoScript;
var target1: Transform;
var speed: float;
var Summon : boolean;
private var selectedCard : GameObject;
var Summoning : boolean;
function Update(){
if (Input.GetMouseButtonDown (1) && showButton){
showButton = false;
}
if (Input.GetMouseButtonDown (0) && !showButton)
{
CheckClick ();
}
if (selectedCard.transform.position == target1.position){
Summon = false;
Screen.lockCursor = false;}
if (Summon == true)
{
var step = speed * Time.deltaTime;
selectedCard.transform.position = Vector3.MoveTowards(selectedCard.transform.position, target1.position, step);
{print("I have been Summoned!");}
Screen.lockCursor = true;
}
}
function OnGUI() {
var e = Event.current;
var x = pos.x - 50; // Calc x and y to center of button
var y = pos.y - 10;
if (showButton && GUI.Button (Rect (x,y - 95, 100, 20), "Summon")) {
print("Summoning");
Summon = true;
showButton = false;
}
}
function CheckClick() {
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit)) {
Debug.Log("Card selected:"+hit.collider.name);
if (hit.collider.tag == "Card"){
selectedCard = hit.collider.gameObject; //Store my selection
}
pos = Camera.main.WorldToScreenPoint(hit.transform.position);
pos.y = Screen.height - pos.y; // convert from Screen to GUI
showButton = true;
}
else {
showButton = false;
return null;
}
}
WHEW! FIXING THINGS YOUR SELF PUTS ME IN A HELL OF A GOOD MOOD!
Thanks for advising me guys.
I'll post it as answered incase someone else have this problem.
Answer by RedDevil · Mar 25, 2014 at 03:47 PM
You can just make the cursor not available during that with : Screen.showCursor = false; and then enable it whenever you want
@RedDevil Alright cool I tried that before I asked but I still couldn't get this to work. and I'm looking into it but I still cant get it right.
For some odd reason when ever I click the GUI Button Summon. $$anonymous$$y mouse just flickers really quickly.
Here's what it looks like.
var e = Event.current;
var x = pos.x - 50; // Calc x and y to center of button
var y = pos.y - 10;
if (showButton && GUI.Button (Rect (x,y - 95, 100, 20), "Summon")) {
print("Summoning");
Summon = true;
showButton = false;
Screen.showCursor = false;
}
}
Does it need to be a update function? or do I need to put a true statement in my static function?
It seems like I cant find a way to get around this shit..
Here's what my entire code looks like with help from a few Unity members.
private var showButton = false;
private var pos : Vector2;
private var hit : RaycastHit;
var Occupied1 : GameObject;
var Occupied2 : GameObject;
var Occupied3 : GameObject;
var Occupied4 : GameObject;
var Occupied5 : GameObject;
var Clicked = false;
var Zone1 : float = 3.546595;
var Zone2 : float = 1.466332;
var Zone3 : float = -0.5914766;
var Zone4 : float = -2.645551;
var Zone5 : float = 3.546595;
var jeq : $$anonymous$$onoScript;
var target1: Transform;
var speed: float;
var Summon : boolean;
private var selectedCard : GameObject;
var Summoned : boolean;
function Update(){
if (Input.Get$$anonymous$$ouseButtonDown (1) && showButton){
showButton = false;
}
if (Input.Get$$anonymous$$ouseButtonDown (0) && !showButton)
{
CheckClick ();
}
if (Summon == true)
{
if (selectedCard.transform.position == target1.position){
Summon = false;}
var step = speed * Time.deltaTime;
selectedCard.transform.position = Vector3.$$anonymous$$oveTowards(selectedCard.transform.position, target1.position, step);
{print("I have been Summoned!");}
}
}
function OnGUI() {
var e = Event.current;
var x = pos.x - 50; // Calc x and y to center of button
var y = pos.y - 10;
if (showButton && GUI.Button (Rect (x,y - 95, 100, 20), "Summon")) {
print("Summoning");
Summon = true;
showButton = false;
Screen.showCursor = false;
}
}
function CheckClick() {
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit)) {
Debug.Log("Card selected:"+hit.collider.name);
if (hit.collider.tag == "Card"){
selectedCard = hit.collider.gameObject; //Store my selection
}
pos = Camera.main.WorldToScreenPoint(hit.transform.position);
pos.y = Screen.height - pos.y; // convert from Screen to GUI
showButton = true;
}
else {
showButton = false;
return null;
}
}
I think it has something to do with my Check Click function.
Please anyone help me.