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 :'(
Answer by zmar0519
Mar 12, 2011 at 01:37 PM
Or, use this. I am trying to do something very similar:
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
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.
it do have mesh collider, but it still can't seem to work x.x
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.
Also, make sure that it is not set to a trigger.
Answer by OrangeLightning
Mar 12, 2011 at 01:16 PM
Why not use:
function OnMouseUp ()
When you click the object with this script attached to it, it will destroy the gameobject clicked on.
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
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
Destroy objects by clicking on them
Object Movement via Mouse Click?
Destroy on touch for iphone
Mouse Click and Spawn object
Run script when object is clicked