示例#1
0
    private void Update()
    {
        if (moving && currentDestination.x > -9999)
        {
            // add some distance
            distanceMoved += speed * Time.deltaTime;

            //move along according to speed;
            shipView.transform.position = Vector2.Lerp(currentLocation, currentDestination, distanceMoved);

            //check if we've reached the goal point
            if (distanceMoved >= 1)
            {
                destinations[destinationIndex].GetMovementEffects(shipModel);
                distanceMoved     = 0;
                destinationIndex += 1;
                // check if we're done moving
                if (destinationIndex >= destinations.Count)
                {
                    moving = false;
                    if (pirateMoving != null)
                    {
                        pirateMoving.FinishedAnimatingMovement();
                    }
                    else
                    {
                        shipModel.FinishedAnimatingMovement();
                    }
                    if (playerToShootOnFinish != null)
                    {
                        pirateMoving.Shoot(playerToShootOnFinish);
                        pirateMoving          = null;
                        playerToShootOnFinish = null;
                    }
                }
                else
                {
                    currentLocation    = currentDestination;
                    currentDestination = destinations[destinationIndex].GetController().GetPosition();
                    FlipShip(currentLocation.x < currentDestination.x);
                }
            }
        }
        else if (!(currentDestination.x > -9999))
        {
            if (pirateMoving != null)
            {
                pirateMoving.FinishedAnimatingMovement();
            }
            if (playerToShootOnFinish != null)
            {
                pirateMoving.Shoot(playerToShootOnFinish);
                shipModel.soundController.SwitchMusic(SoundController.Sound.battle);
                pirateMoving          = null;
                playerToShootOnFinish = null;
            }
        }
    }