- Home /
already asked
Is it possible to use OnMouseDown(collision other) ???
How do i delete this question?
I dont get what you are trying to do but what i think might help is use OnTriggerEnter(Collision collision) and inside it check for On$$anonymous$$ouseDown() and put all the code in. What this will do is check the trigger when the mouse is down !!
so does that mean that my collider has to be touching the object fruit two? im trying to mouse click on an instantiated prefab and check if the tag matches one of the inventory icons already. If it does match then ins$$anonymous$$d of adding the icon to the panel it will increase the number on the icon that is already there. It works fine if I run into the object with my collider touches the fruits collider. But i want to convert my Collision checking to happen with the mouse click ins$$anonymous$$d of me actually walking into the object.
Answer by oscarlundberg · Apr 11, 2016 at 07:20 PM
Your mouse doesn't have a collider so it can't collide. I'm not sure what you want to do but maybe RaycastHit.Collider will work for you.
I have an object that I want to click on. Once it is clicked I want get the tag name. The object is a child. then debug log "I have clicked on object" .
Here is the code now. Hello never prints.
void On$$anonymous$$ouseDown() {
Debug.Log ("hello");
GameObject i;
if(gameObject.tag == "fruit_one")
{
i = Instantiate(inventoryIcons[0]);
i.transform.SetParent(inventoryPanel.transform);
}
else if(gameObject.tag == "fruit_two")
{
i = Instantiate(inventoryIcons[1]);
i.transform.SetParent(inventoryPanel.transform);
}
else if(gameObject.tag == "fruit_three")
{
i = Instantiate(inventoryIcons[2]);
i.transform.SetParent(inventoryPanel.transform);
}
} }
Follow this Question
Related Questions
Make a simple tree 1 Answer
How To Get List of Child Game Objects 14 Answers
accessing all of a colliders parents children 1 Answer
Destroyed child still is referenced. 1 Answer