- Home /
Click on Arrows to Move Object.
I have a Human1 Object and 4 directional Arrow Object (Up, Down, Left, Right)
I want to do the following in one script
OnMouseDown, Check which directional Arrow was Clicked.
Move Human1 according to the directions.
Example code;
OnMouseDown(){
switch(gameobject)
{
up:
Human1 Moves up;
break;
down:
Human1 Moves down;
break;
Left:
Human1 Moves Left ;
break;
Right:
Human1 Moves Right ;
Break;
}//end switch
}//end OnMouseClick
On$$anonymous$$ouseDown() is true when the object the script is attached to is clicked on. If you use this method to get a mouse click, you will need scripts attached to each arrow. When the arrow is clicked you take the appropriate action for that arrow.
Is this Unityscript, and does Unityscript not require the case keyword? Geez.
Answer by haiyo84 · Feb 07, 2013 at 08:41 AM
the problem with using OnMouseDown() on every arrow object will not make any of my object move. Because it is checking only whether I click my left button mouse was clicked.
What I wanted was to check which arrow was being clicked.
I understand that there is another solution to use raycast to check on the position of my mouse.
Sadly I felt it was a little complicated to me, maybe some bright minds can try to guide me on how to get that done?
Your answer
![](https://koobas.hobune.stream/wayback/20220613092201im_/https://answers.unity.com/themes/thub/images/avi.jpg)