hasClicked = false;
function OnMouseDown ()
{
if (hasClicked)
{
hasClicked = false;
//reverse direction here
} else {
hasClicked = true;
//move this direction
}
}
Now, with transform.position you’re actually “teleporting” the character in that direction. I’m unsure if this is the effect you wanted, but I just thought I’d make you aware.
I will work with both examples and learn from then. I know I had to use an if statement, but being new at this I really wasn’t sure about it.
And yes I know I would be teleporting instead of an animated move. I am just learning as much as possible with all different scenarios. I will work on an animated move next.
Thanks again for the information it will be useful during the learning process.
Ok well I looked up the Input.GetMouseButtonDown in the scripting reference and it says Left is 0, 1 is right and 2 for middle.
But I changed the value to one and I am Left clicking on the object and it works, but if I right click in open space it also works on the object. Now I am confused even more???
I want the command confined to clicking on the object only.
appels,
I tried you version first and it works great. I had to change the value after Input.GetMouseButtonDown (0) to 1.
If the value was on 0 I had to click outside the game object I wanted it to affect. If I changed it to 1 then I had to click the game object to get it to work.
Could you please explain that last part of the script and what was the difference between 1 and 0. I am assuming true or false but I am not sure.
You are stating the OnMouseDown, if the objects current position is equal to (107,2.5,66)
When you click change it to this (107,0,66)
else ( meaning that if it is not at (107,2.5,66) then move it to (107,2.5,66)