- Home /
Translate to a distance then rotate and go back to earlier position on x-axis
I am considering a plane on which i have placed an image and I want this plane to move along x-axis.My problem here is that when i click on the plane it should move to a certain distance and then flip or rotate the plane and after the rotation it should move back to the original location.For example: If image is of a toy I want the toy to move 5 units to the left then the image of the toy should rotate to 180 and then again move back 5 units to right to its original position and this process should happen when i click on the plane/image.I am new to programming and also unity so i am clueless how should i do that?Any thoughts?Please let me know.
can someone please guide me?? Is there any simpler way to do it????
var moveforward;
function Start(){
moveforward = false;
}
function Update(){
if(moveforward)
forwardmovement();
else if(!moveforward)
backwardmovement();
}
function forwardmovement(){
transform.position.x += 1 * Time.deltaTime;
yield WaitForSeconds(1);
moveforward = false;
}
function backwardmovement(){
transform.position.x -= 1 * Time.deltaTime;;
yield WaitForSeconds(1);
moveforward = true;
}
this lets my image to move along x axis but after it reaches 1 unit i want it to rotate and then move -1 unit back to its original position.
http://wiki.unity3d.com/index.php?title=$$anonymous$$oveObject
Also you can use iTween. It is free in the Asset store.
I converted your 'Answer' to a comment. By adding follow-up information to your question as an answer, it made it appear that you question already had one answer...and therefore you would be less likely to get an answer.
if not at target go to target
if at target start rotation with coroutine
while coroutine -> wait
if coroutine over -> target = newTarget
Back to 1
You have your two target in an array so that you can easily get from one to the other.
But how should my code be like i am very new to program$$anonymous$$g and unity and I am understanding the logic but not exactly able to implement it.
Your answer