A action lib for unity
public float speed;
void Update() {
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
What if you want to move an gameObject go through an list of postion? Below is an example how to do it.
public Vector3[] positions;
public Transform ObjectToMove;
public float MoveSpeed = 8;
Coroutine MoveIE;
void Start()
{
StartCoroutine(moveObject());
}
IEnumerator moveObject()
{
for (int i = 0; i < positions.Length; i++)
{
MoveIE = StartCoroutine(Moving(i));
yield return MoveIE;
}
}
IEnumerator Moving(int currentPosition)
{
while (ObjectToMove.transform.position != positions[currentPosition])
{
ObjectToMove.transform.position = Vector3.MoveTowards(ObjectToMove.transform.position, positions[currentPosition] , MoveSpeed * Time.deltaTime);
yield return null;
}
}
//some mess code
MTActionLib use command pattern to simplify above movement, you don't need create extra script to deal with the actions, only need to replace mess code like below.
gameObject.RunActions(action1,action2,action3);
The action above could be an movement, an transformation, an color changing, an fade process, an callback function or even any number combination of all actions
using MTUnity.Actions;
cube.RunActions(new MTMoveTo(2f,posA));
cube.RunActions(new MTMoveTo(2f,posA),new MTMoveTo(2f,posB));
cube.RunActions(new MTMoveTo(2f,posA),new MTMoveTo(2f,posB));
cube.RunActions(new MTSpawn(new MTMoveTo(1f,posA),new MTScaleTo(new Vector3(2f,2f,2f)));