Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (preparingKegStand)
        {
            prepareTimer -= Time.deltaTime;

            if (prepareTimer <= 0.0f)
            {
                preparingKegStand = false;
                settingUpKegStand = true;
                SetUpKegStand();
            }
        }
        if (settingUpKegStand)
        {
            startTimer -= Time.deltaTime;

            if (startTimer <= 0.0f)
            {
                settingUpKegStand = false;
                StartKegStand();
            }
        }
        if (drinking)
        {
            drinkingTimer -= Time.deltaTime;

            if (drinkingTimer <= 0.0f)
            {
                drinkingTimer = .2f;
                uiController.DrinkBeer(2);
            }

            pointsTimer -= Time.deltaTime;

            if (pointsTimer <= 0.0f)
            {
                pointsTimer = 1.0f;
                pointsCounter++;

                var newPoints = 10 + (pointsCounter * 5);
                uiController.AddPartyPoints(
                    newPoints, new Vector3(transform.position.x, transform.position.y + 1.0f, -2.0f));
            }


            // If a tap, find what was clicked on and act on it
            if (Input.GetMouseButtonUp(0))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit))
                {
                    switch (hit.collider.name)
                    {
                    case "StopKegStand":
                        StopKegStand();
                        break;
                    }
                }
            }
        }
    }
    // Returns 1 if island, 2 if freshman cup, 3 if water cup, 4 if other
    int CheckBallInCup()
    {
        List <int> rimJobs = new List <int>();

        for (int i = 0; i < 10; i++)
        {
            if (cupsPlaced[i])
            {
                var ball        = ballParent.transform.Find("PingPongBall");
                var ballCenterX = ball.transform.position.x;
                var ballCenterY = ball.transform.position.y;
                if (ballCenterX >= (cups[i].transform.position.x + cupLeftMost) &&
                    ballCenterX <= (cups[i].transform.position.x + cupRightMost) &&
                    ballCenterY >= (cups[i].transform.position.y + cupBottomMost) &&
                    ballCenterY <= (cups[i].transform.position.y + cupTopMost))
                {
                    // Play ball in cup sound
                    inCupSFX.GetComponent <AudioSource>().Play();
                    // Remove cup in global controller
                    cupsPlaced[i] = false;
                    // Play "moving" animation
                    cups[i].GetComponent <Animator>().Play("MadeBall");
                    // Start timer until animation is over
                    cupAnimTimer = defaultCupAnimTime;
                    // Keep current cup for future use
                    cupIndex = i;
                    // Add party points
                    if (uiController)
                    {
                        uiController.AddPartyPoints(10, cups[i].transform.position);
                    }

                    // Kill off the ball
                    ResetOpponent();

                    if (isIsland(cupIndex))
                    {
                        return(1);
                    }
                    if (isFreshman(cupIndex))
                    {
                        return(2);
                    }
                    // if cupIndex == 10, don't think this is implemented yet
                    //   return 3
                    return(4);
                }
                else if (ballCenterX >= (cups[i].transform.position.x - (cups[i].GetComponent <Renderer>().bounds.size.x *6 / 10)) &&
                         ballCenterX <= (cups[i].transform.position.x + (cups[i].GetComponent <Renderer>().bounds.size.x *6 / 10)) &&
                         ballCenterY >= (cups[i].transform.position.y) &&
                         ballCenterY <= (cups[i].transform.position.y + (cups[i].GetComponent <Renderer>().bounds.size.y *6 / 10)))
                {
                    rimJobs.Add(i);
                }
            }
        }

        // If you missed but got close to a cup, show it rattle
        if (rimJobs.Count > 0)
        {
            // Play "moving" animation
            foreach (int rimJob in rimJobs)
            {
                cups[rimJob].GetComponent <Animator>().Play("CupNearMiss");
            }
            return(5);
        }

        return(0);
    }