// 移动人物。 public void MoveCharacter(CharacterController character) { Vector3 destination = character.GetDestination(); GameObject gameObject = character.gameObject; Vector3 currentPosition = character.transform.position; //横向直线运动和纵向直线运动的转折点。 Vector3 pivotPosition = currentPosition; if (destination.y > currentPosition.y) { pivotPosition.y = destination.y; } else { pivotPosition.x = destination.x; } // 创建序列动作来表示人物的折线运动:横向的直线运动、纵向的直线运动。 Action action1 = MoveToAction.GetAction(gameObject, null, pivotPosition, 20); Action action2 = MoveToAction.GetAction(gameObject, null, destination, 20); SequenceAction action = SequenceAction.GetAction(this, new List <Action> { action1, action2 }); AddAction(action); }
// 移动船只。 public void MoveBoat(BoatController boat) { // 创建船的直线运动。 MoveToAction action = MoveToAction.GetAction(boat.gameObject, this, boat.GetDestination(), 20); AddAction(action); }
// 创建 MoveToAction 。 public static MoveToAction GetAction(GameObject gameObject, IActionCallback callback, Vector3 destination, float speed) { MoveToAction action = CreateInstance <MoveToAction>(); // 设置需要进行直线运动的游戏对象。 action.gameObject = gameObject; action.transform = gameObject.transform; action.callback = callback; // 设置直线运动的终点。 action.destination = destination; // 设置直线运动的速度。 action.speed = speed; return(action); }