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 Jopz · Mar 12, 2011 at 01:13 PM · objectmousedestroyclickusing

Destroy object using mouse click(raycast to detect collision)

I've been in this problem for 2 weeks now and now its pissing me off ~__~

I'm trying to destroy a game object by using mouse click, i have done it using the usual mouseclick destroy game object method. but i want the object to be destroyed when i cliked "on" it.

Raycast probably is the best for it since it's as thin as needle (lol). now i want the raycast to be at my mouse pointer so i can use it to detect collision... can someone help me with this :'(

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
0
Best Answer

Answer by zmar0519 · Mar 12, 2011 at 01:37 PM

Or, use this. I am trying to do something very similar:

function OnMouseOver()
{
 if(Input.GetMouseButtonDown(0))
 {
  Destroy(gameObject);
 }
}
Comment
Add comment · Show 7 · 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 Jopz · Mar 12, 2011 at 03:40 PM 0
Share

thanks for the codes... but it seem not to work... i've tried it in a dummy scene. yeah it works, but when i'm using it on imported game objects it can't seem to work... x.x

avatar image zmar0519 · Mar 12, 2011 at 04:02 PM 0
Share

is there a collider attatched to your object? if not, and it is imported, just use a mesh collider on it and it should work fine.

avatar image Jopz · Mar 12, 2011 at 04:48 PM 0
Share

it do have mesh collider, but it still can't seem to work x.x

avatar image NewfieJoe · Mar 12, 2011 at 06:51 PM 0
Share

Is the script and the collider in the same place on the object hierarchy? If the collidor is on a child object I don't think it will trigger the script.

avatar image zmar0519 · Mar 13, 2011 at 12:05 AM 0
Share

Also, make sure that it is not set to a trigger.

Show more comments
avatar image
0

Answer by FLASHDENMARK · Mar 12, 2011 at 01:16 PM

Why not use:

function OnMouseUp ()
{
Destroy(gameObject);
}

When you click the object with this script attached to it, it will destroy the gameobject clicked on.

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 Jopz · Mar 12, 2011 at 03:02 PM 0
Share

yeah... it seems to be working when i'm using it on a dummy.. like simple cube... but when i'm using it on imported game objects it can't seem to work... x.x

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

No one has followed this question yet.

Related Questions

Destroy objects by clicking on them 1 Answer

How to make object clickable when user enter collider ? 0 Answers

Destroying specific clone object while not destroying others on screen 5 Answers

How to attach objects using a mouse click on one side, and object only attaches to that one side? 0 Answers

Object Movement via Mouse Click? 3 Answers


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