- Home /
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 :'(
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);
}
}
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.
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.
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
Follow this Question
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