Esempio n. 1
0
    // Manage score computation when the ball enters the cave
    void OnCollisionEnter(Collision collision)
    {
        GameObject obj = collision.gameObject;

        if (obj.tag == "Ball")
        {
            /***************** Ball collision control *****************/

            // Return the ball to the storage
            Debug.Log("Ball " + obj.name + " in the cave");
            obj.transform.position = GameObject.Find("RightLane/Lane/ball_recovery_vertical_tunel_001/ball return gate").transform.position;
            obj.GetComponent <Rigidbody>().AddForce(new Vector3(0, 60, 0), ForceMode.Impulse);

            // Start fallen pins accounting, by recoverying them so that they could be countable
            recoveryFallenPins();
            if (!parameters.IsLastFrame)
            {
                // Go to the next frame
                parameters.initNextRound();
            }
            else
            {
                // End the game and send the player to the menu
                endGame();
                sendPlayerToMenu();
            }
        }

        if (obj.tag == "Pin")
        {
            /***************** Pin collision control *****************/

            Debug.Log("Pin felt: " + obj.name);

            // Increment the fallen pins of the frame's round
            parameters.incrementFallenPins();
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        // Recover the fallen Pins and count them
        if (performPinRecovery)
        {
            if (timer >= 5.0f)
            {
                // Start fallen pins accounting, by recoverying them so that they could be countable
                if (recoveryFallenPins())
                {
                    turn = 1;
                    if (!parameters.IsLastFrame)
                    {
                        if (fallenPins.Count >= 10)
                        {
                            fallenPins.Clear();
                        }
                        // Go to the next frame
                        parameters.initNextRound();
                    }
                    else
                    {
                        // End the game and send the player to the menu
                        endGame();
                        sendPlayerToMenu();
                    }

                    performPinRecovery = false;
                    timer = 0.0f;
                }
            }
            else
            {
                timer += Time.deltaTime;
            }
        }
    }