- Home /
Moving an object with one key press
i already read this and try to implement the code made by skovacs1, but still couldnt come into anything,, oh man, i'm really terrible on code..
http://answers.unity3d.com/questions/27369/how-to-move-an-object-from-point-a-to-point-b-with.html (i found out the thread is alrdy on 2010, and i read it somewhere isnt it better to ask new one ? sorry if i'm wrong or "repost"-ing)
please can someone explain this to me? i made some project, the system is fighting-battle-turn that needs the object to move towards enemies, attacking and back to its start position..
i used this and still can't figured out how it goes.. and also, could this done inside if(GUI.Button(Rect(50,300,70,30),"Attack 1")) ?? so when i press the button, the object will move..
thanks before.
Answer by Bryan-Legend · Nov 11, 2013 at 10:50 PM
I'd try to do the delayed animation using yield coroutines:
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Coroutines_26_Yield.html
Something like this:
transform.position += new Vector3(1,0,0);
yield WaitForSeconds (2);
transform.position += new Vector3(-1,0,0);
I don't know how often OnGUI gets called so it might not work there, but it should bee good to use in Update.
i still dont get how to do it.. so i should add in update and place it on the object i want to move?
transform.position += new Vector3(1,0,0);
yield WaitForSeconds (2);
transform.position += new Vector3(-1,0,0);
and how do i connect it by pressing a button? because as far as i know, i only understand how to execute an instruction by clicking button, using if(GUI.Button()){-statement-}
thanks for the reply thou, made me know about yield :)
Your answer
