Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by lanostraliberta · Mar 02, 2012 at 06:40 PM · buttonmousedisable

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image THRILLHOUSE · Jun 16, 2013 at 12:25 AM 0
Share

I need this but in C#!

avatar image
0

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]

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges