Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Derek · Mar 26, 2011 at 03:09 PM · objectdisappearclicked

How can I make an object disappear when clicked?

Just as the ultra-noob question title states. I'm sure there is a simple script, but I can't find it. How can I make my gameobject cube disappear when I click it?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by efge · Mar 26, 2011 at 03:22 PM

Attach a simple collider and this script to the object. Choose one of the options.

function OnMouseDown () {
  gameObject.active = false;
  //Destroy(gameObject);
  //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 AngryOldMan · Mar 26, 2011 at 03:29 PM 1
Share

this answer is much less effort than raycasting :)

avatar image tool55 · Mar 26, 2011 at 05:52 PM 0
Share

Interesting. Haven't used this before. Looks like this function is a shorthand way of doing the raycast for you. In the scripting reference it says that this won't work on Ignore Raycast layers. It also says it doesn't work on iPhone apps. But otherwise seems like a good way of handling mouse click events. Thanks!

avatar image Derek · Mar 26, 2011 at 06:00 PM 0
Share

Thanks, it worked great!

avatar image tool55 · Mar 26, 2011 at 06:24 PM 0
Share

Just as an added thought, On$$anonymous$$ouseDown() doesn't seem to give you control of depth (z axis) so you'd have to do your own raycast if you only want objects closer than a certain distance to be clickable.

avatar image
0

Answer by tool55 · Mar 26, 2011 at 03:18 PM

Check out this link about raycasting. This will make your object clickable:

http://unity3d.com/support/documentation/ScriptReference/Collider.Raycast.html

You'll then want to enable or disable the renderer if the raycast hits something

Here's the link for that:

http://unity3d.com/support/documentation/ScriptReference/Renderer-enabled.html

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
avatar image
0

Answer by Tommy · Mar 26, 2011 at 05:38 PM

Maybe something like this?:

var objToDel : GameObject; <--- But "cube" here function Update() { var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; if (collider.Raycast (ray, hit, 100.0)) { delta = hit.gameObject.name; }

if (delta == objToDel.gameObject.name) { objToDel.active = false; } }

Not quite sure, can't verify, not @ my computer.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Sphere disappear after build 0 Answers

object dissappear and reappear 1 Answer

Player Moves Away = Object Disappear Scrpit - Help 1 Answer

Make Animated object disappear after it animates 1 Answer

Objects disappear after building 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