void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.tag == "ball" || collider.gameObject.tag == "multiball")
        {
            //when the ball hits the powerup, the powerup activates

            if (rand == 0) //DEX MODIFIER POWER UP

            //find all the enemies so they know to increase their dex modifier
            {
                enemies = GameObject.FindGameObjectsWithTag("enemy");

                foreach (GameObject enemy in enemies)
                {
                    dexPower = enemy.GetComponent <enemyBehavior>();


                    dexPower.dexPowerup();
                }
            }

            if (rand == 1) //LARGER BALL

            //find all the balls, no matter what they're tagged
            {
                string[] allballs = { "ball", "multiball" };

                foreach (string tag in allballs)
                {
                    GameObject[] balls = GameObject.FindGameObjectsWithTag(tag);

                    foreach (GameObject anyball in balls)
                    {
                        bigball = anyball.GetComponent <ballcontrol>();

                        bigball.largerBall();
                    }
                }
            }

            if (rand == 2) //MULTIBALL
            {
                multiball.Multiball();
            }



            Destroy(gameObject, 0f); //destroy the powerup immediately so the ball doesn't bounce off of it
        }

        if (collider.gameObject.tag == "Respawn")
        {
            Destroy(gameObject, 0f);
        }
    }
Beispiel #2
0
    IEnumerator GameLoop()
    {
        Debug.Log(playerPuttCount());
        while (playerPuttCount() > 1)
        {
            switch (turn)
            {
            case TurnMode.Placement:
                canvasController.TogglePowerBar(false);
                //for each player
                List <PlayerStats> players = sortedPlayers();
                foreach (PlayerStats player in players)
                {
                    //wait for controller confirmation
                    if (player.PowerUp != null)
                    {
                        while (true)
                        {
                            if (Input.anyKey)
                            {
                                break;
                            }
                            yield return(null);
                        }

                        //start timer
                        float startTime = Time.time;

                        //if player canputt is false give a random power up for placement

                        cameraMover.GetComponent <camera>().activePlayer = player;
                        canvasController.ChangePlayerText(player.name, turn);

                        //allow placement


                        //REPLACE WITH TIME DURATION VARIABLE
                        //while timer
                        while ((Time.time - startTime < waitTime))
                        {
                            canvasController.ShowTime(waitTime - (Time.time - startTime));
                            //display timer ui
                            // Debug.Log("Turn timer: " + (Time.time - startTime));

                            //invoke function on character for power placement. pass in player

                            if (Input.GetKeyDown("space"))
                            {
                                trap.Play();
                                startTime -= 20;
                            }
                            yield return(null);
                        }

                        canvasController.HideTime();

                        //end placement
                        cameraMover.GetComponent <camera>().PlacePowerUp();

                        //end turn UI
                        //Debug.Log("Player turn is finished");
                    }
                }

                //change turnmode to putting
                turn = TurnMode.Putting;
                break;

            case TurnMode.Putting:
                canvasController.RemovePowerUpText();
                List <PlayerStats> players2 = sortedPlayers();
                ballcontrol        bc       = Ball.GetComponent <ballcontrol>();
                foreach (PlayerStats player in players2)
                {
                    if (player.canPutt)
                    {
                        canvasController.PuttMessage("Press any key to start putting!");
                        canvasController.TogglePowerBar(true);

                        //prompt for controller confirmation
                        //Debug.Log("Press a key to start your turn : " + player.name);
                        canvasController.ChangePlayerText(player.name, turn);

                        while (true)
                        {
                            if (Input.anyKey)
                            {
                                break;
                            }
                            yield return(null);
                        }

                        //////!!!!!!!!!!!!!!!!!!!!!!!!!
                        //bc.enabled = true;

                        //wait for putt input
                        canvasController.PuttMessage("Press left mouse button to putt!");
                        //Debug.Log("waiting for putt input");

                        bc.ActiveGolfer = player;
                        while (!bc.inPlay)
                        {
                            //Debug.Log("Checking if ball was hit");
                            if (bc.inPlay)
                            {
                                break;
                            }
                            yield return(new WaitForSeconds(1));
                        }
                        canvasController.PuttMessage("Ball was hit!");
                        canvasController.TogglePowerBar(false);

                        //Debug.Log("waiting for ball to finish moving");
                        //wait for ball movement to finish
                        //while (Ball.GetComponent<Rigidbody>().velocity.magnitude == 0) {
                        //    yield return null;
                        //}

                        //double check
                        float timer = 0;
                        while (timer < 2)
                        {
                            timer += Time.deltaTime;
                            if (Ball.GetComponent <Rigidbody>().velocity.magnitude > 0)
                            {
                                timer = 0;
                            }
                            yield return(null);
                        }
                        //Debug.Log("Ball is now stopped we think");

                        //set the ball to not in play
                        bc.inPlay       = false;
                        bc.ActiveGolfer = null;

                        if (bc.inHole)
                        {
                            //set player can putt bool to false
                            player.canPutt = false;
                            //show ui for player eliminated
                            //Debug.Log("Show ui that this player is eliminated");
                            canvasController.PuttMessage(player.name + " is eliminated");
                            canvasController.ShowDead(player.name);
                            canvasController.StartCoroutine("DunkedSon");

                            yield return(new WaitForSeconds(messageTime));

                            //if more than one player can putt
                            if (playerPuttCount() > 1)
                            {
                                //Debug.Log("Reset scene for remaining players");
                                canvasController.PuttMessage("Setting up next round!");
                                yield return(new WaitForSeconds(messageTime));

                                //delete all power ups in game world
                                GameObject[] powerups = GameObject.FindGameObjectsWithTag("PowerUp");
                                for (var i = 0; i < powerups.Length; i++)
                                {
                                    Destroy(powerups[i]);
                                }

                                //reset ball position
                                bc.NextLevel();
                                break;
                            }
                            else
                            {
                                canvasController.PuttMessage(player.name + ", you lose!");
                            }
                        }
                        ////////!!!!!!!!!!!!!!!!!!!!!!
                        //bc.enabled = false;
                    }
                }

                //get all powerups in the scene - send message to increase integer for turn count

                if (playerPuttCount() > 1)
                {
                    turn = TurnMode.Placement;
                }
                else
                {
                    turn = TurnMode.GameOver;
                }

                break;

            default:
                callWinner();
                break;
            }
        }

        //else remaining player wins
        callWinner();
    }