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 /
This question was closed Dec 21, 2013 at 05:18 PM by clunk47 for the following reason:

The question is answered, right answer was accepted

avatar image
-1
Question by skullred · Dec 01, 2013 at 12:28 PM · gameobjectmousemouseclick

action to click the left mouse

without using the raycast would like to achieve something like this: When I click the left button of the mouse on a GameObject I would like something to happen, for example, I click on a cube, and it disappears. What is the script that I can accomplish this? possibly in C #

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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Dec 01, 2013 at 04:01 PM

You are looking for OnMouseDown():

 using UnityEngine;
 using System.Collections;
 
 public class Click : MonoBehaviour {
     void OnMouseDown() {
         renderer.enabled = false;
     }
 }
Comment
Add comment · Show 4 · 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 skullred · Dec 01, 2013 at 04:33 PM 0
Share

This works for all GameObject, but how do I get it to work only with those who have a particular name?

avatar image z3nth10n · Dec 01, 2013 at 04:39 PM 0
Share

You had to create a public variable and assign the GameObject to the inpector, and later call the named variable por example (public GameObject cube) and On$$anonymous$$ouseDown cube.enabled=false;

avatar image robertbu · Dec 01, 2013 at 06:44 PM 0
Share

@Ikillnukes - No, you don't need public game object as you describe. The code above works fine, and does what he requested. Put this scrip on a game object, run the app. When you click on the game object, it will disappears. Your suggested change and your code below would only be necessary if you want some other game object to disappear. That is you click on cube1 and it makes cube2 disappear.

avatar image clunk47 · Dec 21, 2013 at 05:17 PM 0
Share

Just use what @robertbu showed you and check the name lol.

     using UnityEngine;
     using System.Collections;
      
     public class Click : $$anonymous$$onoBehaviour 
     {
         void On$$anonymous$$ouseDown() 
         {
             if(name == "Cube")
                 renderer.enabled = false;
         }
     }

Follow this Question

Answers Answers and Comments

18 People are following this question.

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

Related Questions

mouse click obj to initiate action, then locking the obj so action cant be repeated 1 Answer

MouseClick and gameObject 1 Answer

Moving GameObjects with mouse and check contains 0 Answers

Distance interaction 0 Answers

Raycast hit not detected on cube 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