- Home /
How can i disable left button mouse, when i click on GameObject?
Hello guys, i've a question for you: How can i disable left button mouse, when i click on GameObject?
I'm thinking to insert the code inside the gameObject, but what code (in JavaScript) for stop the left button mouse after click? Thanks.
Answer by Kleptomaniac · Mar 03, 2012 at 05:32 AM
I'm not sure if you actually mean that you want to disable all functionality of the left mouse button or if you wanted to just disable the ability to click on the gameObject. In this case the code I included just disables the ability to receive input in terms of clicking the gameObject.
var canClick : boolean = true;
function Update () {
if (Input.GetMouseButtonDown(0) && canClick) {
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, 100)) {
if (hit.collider.gameObject.tag == "foo") { //Only needed if you want to click on a specific object and disable
canClick = false;
}
}
}
}
If, however, you wanted it so all left mouse button functionality was disabled, then you would just include anything that uses the left mouse button within your game within if (Input.GetMouseButtonDown(0) && canClick) {
This, however, is most definitely not the best way of doing things. If you were to provide some more information, perhaps we could help you more.
Good luck, Klep
Answer by lanostraliberta · Mar 03, 2012 at 03:22 PM
Mmm, Does not work. Nothing Happened. About your question, i would like click on gameObject and ALL functionality was disable.
I'm using a Java Script code. When i Click on gameObject, there's a fade out and change level.
Here:
[quote] var isQuitButton = false; var mySound : AudioSource;
public var fadeOutTexture : Texture2D; public var fadeSpeed = 0.3; var drawDepth = -1000; private var alpha = 1.0; private var fadeDir = -1;
function OnGUI(){ alpha += fadeDir fadeSpeed Time.deltaTime;
alpha = Mathf.Clamp01(alpha);
GUI.color.a = alpha;
GUI.depth = drawDepth;
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeOutTexture); }
function MyWaitFunction (delay : float) {
var timer = Time.time + delay;
while (Time.time < timer) {
yield;
} }
function OnMouseEnter() { //change the color of the text renderer.material.color = Color.red; }
function OnMouseExit() { //change the color of the text renderer.material.color = Color.white; }
function OnMouseUp() { if( isQuitButton ) { alpha=-1; fadeOut();
Application.Quit(); } else {
mySound.Play();
alpha=-1; fadeOut();
yield MyWaitFunction (3.0); Application.Quit(); } }
function fadeIn(){ fadeDir = -1;
}
function fadeOut(){
fadeDir = 1;
}
[/quote]
Your answer
Follow this Question
Related Questions
Disable Button for a while 2 Answers
Button being pressed but an other button gets the effect. 0 Answers
Overlapping GUI Button priority 3 Answers
How can I stop the middle mouse button from zooming out when I single click it inside the editor? 2 Answers
Problems at using touch and buttons inputs,Problems at using touch input on Android 1 Answer