Exemple #1
0
    bool CheckGameOver()
    {
        bool gameOver = false;

        //ball falls over line
        RaycastHit2D[] hitsLast = Physics2D.RaycastAll(playerLine.transform.position + playerLine.GetOrCreateCurrentLine().GetLastPos(), playerLine.GetOrCreateCurrentLine().GetLastDirection());
        foreach (RaycastHit2D hit in hitsLast)
        {
            if (hit.collider != null && hit.collider.tag == "Ball")
            {
                gameOver = true;
            }
        }
        RaycastHit2D[] hitsFirst = Physics2D.RaycastAll(playerLine.transform.position + playerLine.GetOrCreateCurrentLine().GetFirstPos(), playerLine.GetOrCreateCurrentLine().GetFirstDirection());
        foreach (RaycastHit2D hit in hitsFirst)
        {
            if (hit.collider != null && hit.collider.tag == "Ball")
            {
                gameOver = true;
            }
        }

        //ball goes back
        if (gameOverOnGoingBack)
        {
            if (playerBall)
            {
                Vector2 velo = playerBall.GetComponent <Rigidbody2D>().velocity;
                if (velo.x < 0)
                {
                    gameOver = true;
                }
            }
        }

        if (gameOver)
        {
            StopBall();
            GameManager.Instance.GameOver();
        }

        return(gameOver);
    }