履歴の配列を
List<int> btnHistory;
0:右 1:左 2:上 3:下としておきました
都合に合わせてgetDirを改変したり
int[] btnHistoryに書き換えるなりしてください
このスクリプトを動かしたい物体に付けて
ボタンのスクリプトのインスペクターで指定してから
btnHistoryを設定したあと.Activate()すれば動き出します
C#
1public class MovingObj:MonoBehavior{
2int count;
3Vector3 target;
4Vector3 tempPos;
5float timestep=1;
6float t=0;
7Vector3 getDir(int i){
8switch(i){
9case 0:
10return new Vector3(1,0,0);break;
11case 1:
12return new Vector3(-1,0,0);break;
13case 2:
14return new Vector3(0,1,0);break;
15 case 3:
16return new Vector3(0,-1,0);break;
17}
18return Vector3.zero;
19}
20bool activated;
21public List<int> btnHistory;
22public void Activate(){
23activated=true;
24tempPos=transform.position;
25targetPos=getDir(btnHistory[0])+tranfrom.position;
26}
27void Update(){
28 if(!activated)return;
29 transform.position=Vector3.Lerp (tempPos,targetPos,t)
30 t+=Time.deltaTime/timestep;
31 if(t>1){
32 count++;
33 if(count>=btnHistory.Count){
34activated=false;
35return;
36
37}
38 targetPos=tempPos+getDir(btnHistory[count]);
39
40 t=0;
41 }
42}
43}