// Check colider with mapLimitLayer or objectsLayer for stop player movement
    private bool GetNextPositionToMove(Axis direction, float moveY, float moveX)
    {
        Vector3 moveTo = new Vector3();

        if (direction == Axis.X)
        {
            moveTo = moveToPoint.position + new Vector3(moveX, 0f, 0f);
            player.LastDirectionMovement = Axis.X;
            player.LastValueMovement     = moveX;
        }
        else if (direction == Axis.Y)
        {
            moveTo = moveToPoint.position + new Vector3(0f, moveY, 0f);
            player.LastDirectionMovement = Axis.Y;
            player.LastValueMovement     = moveY;
        }

        if (!Physics2D.OverlapCircle(moveTo, 0.2f, mapLimitLayer))
        {
            // Check colider with checkPointLayer
            Collider2D checkPoint = Physics2D.OverlapCircle(moveTo, 0.2f, checkPointLayer);
            if (checkPoint != null && checkPoint.gameObject.CompareTag(gameObject.tag))
            {
                moveToPoint.position = moveTo;
                return(false);
            }
            else if (checkPoint != null && !checkPoint.gameObject.CompareTag(gameObject.tag))
            {
                GameSounds.PlayerSound(GameSounds.Sound.PlayerBlock);
                return(false);
            }

            // Check colider with squareLayer
            Collider2D square = Physics2D.OverlapCircle(moveTo, 0.2f, squareLayer);
            if (square != null && square.gameObject.CompareTag(gameObject.tag))
            {
                GameSounds.PlayerSound(GameSounds.Sound.PlayerBlock);
                return(false);
            }
            else if (square != null && !square.gameObject.CompareTag(gameObject.tag))
            {
                GameSounds.PlayerSound(GameSounds.Sound.PlayerChange);
                moveToPoint.position = moveTo;
                return(false);
            }

            moveToPoint.position = moveTo;
            return(true);
        }
        else
        {
            GameSounds.PlayerSound(GameSounds.Sound.PlayerMovement);
        }
        return(false);
    }
Beispiel #2
0
 public void CompleteLevel()
 {
     lvlComplete = true;
     pauseGame   = true;
     GameSounds.PlayerSound(GameSounds.Sound.LvLWin);
     completeLevelUI.SetActive(true);
     SetScoreValue();
     if (PlayerPrefs.GetInt("LevelSelect") >= PlayerPrefs.GetInt("LastLevelComplete"))
     {
         PlayerPrefs.SetInt("LastLevelComplete", PlayerPrefs.GetInt("LastLevelComplete", 1) + 1);
     }
 }