Exemplo n.º 1
0
        public void OnFixedUpdate()
        {
            toPosition.DoWhenAbsent(() =>
            {
                var target = Vector2.zero;
                if (Position.PlayerLocation.Equals(gunDefinition.ToPosition))
                {
                    GameProvider.GetGameView().ToMaybe()
                    .Do(game =>
                    {
                        var playerPoint = game.GetPlayerPoints().Choose();
                        var tileSize    = CanvasHelper.GetTileSize();
                        var multiplier  = random.Next(2) == 1 ? 1 : -1;
                        if (CanvasHelper.IsLeft(playerPoint.Position) ||
                            CanvasHelper.IsRight(playerPoint.Position))
                        {
                            target = playerPoint.ScreenPosition +
                                     new Vector2(0f, random.Next((int)(tileSize.y)) * multiplier);
                        }
                        else
                        {
                            target = playerPoint.ScreenPosition +
                                     new Vector2(random.Next((int)(tileSize.x * 2)) * multiplier, 0f);
                        }
                    });
                }
                else
                {
                    target = CanvasHelper.GetCanvasPosition(gunDefinition.ToPosition, view.MainRectTransform);
                }

                toPosition = target.ToMaybe();
                view.RotateTowards(target);
            });
        }