Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (!CheckReady())
        {
            foreach (Player p in players)
            {
                if (p.GetButtonDown("Action"))
                {
                    ready[p.id] = !ready[p.id];
                    if (ready[p.id])
                    {
                        source.Stop();
                        source.clip = clips[p.id];
                        source.Play();
                    }
                    readyText[p.id].text = ready[p.id] ? "Ready" : "Not Ready";
                }
            }

            if (CheckReady())
            {
                timer.ResetClock();
                countDownText.gameObject.SetActive(true);
            }
        }
        else
        {
            timer.IncrementTimer();
            int time = (int)timer.CurrentTime;
            countDownText.text = time.ToString();
            if (timer.TimeExpired())
            {
                source.PlayOneShot(clips[4]);
                SceneManager.LoadScene(2);
            }
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (!timer.TimeExpired())
        {
            timer.IncrementTimer();
            timerText.text = ((int)timer.CurrentTime).ToString();
            //Updating Aims postions
            for (int i = 0; i < 4; i++)
            {
                //get the Input from Vertical axis and Horizontal Axis
                userinput = new Vector2(p_input[i].GetAxis("HorizontalStick") * speed * Time.deltaTime, p_input[i].GetAxis("VerticalStick") * speed * Time.deltaTime);
                //update the position
                p_aims[i].GetComponent <Transform>().Translate(userinput);
            }


            //Do we need a new tomato ?
            if (tomato_iswaiting)
            {
                tomato_force = new Vector2(UnityEngine.Random.Range(-500.0f, 500.0f), 900.0f);
            }
            tomato_iswaiting = false;
            tomato_killed    = false;
            //Adding the force to the tomato
            if (!tomato_killed)
            {
                obj_tomato.GetComponent <Rigidbody2D>().WakeUp();
                obj_tomato.GetComponent <Rigidbody2D>().AddForce(tomato_force * Time.deltaTime);
            }
            //Is the tomato outside of the play area ? If, so, reset sprite and position
            if (obj_tomato.transform.position.x > 14 || obj_tomato.transform.position.x < -14 || obj_tomato.transform.position.y > 8 || obj_tomato.transform.position.y < -12 || tomato_killed)
            {
                tomato_pos.x = UnityEngine.Random.Range(-5.0f, 5.0f);
                tomato_pos.y = -6;
                obj_tomato.GetComponent <Rigidbody2D>().Sleep();
                obj_tomato.GetComponent <SpriteRenderer>().sprite = tomato[0];
                obj_tomato.GetComponent <Rigidbody2D>().MovePosition(tomato_pos);
                tomato_iswaiting = true;
            }


            //When press ACTION, does it hit ? If it does, update points
            for (int i = 0; i < 4; i++)
            {
                if (!tomato_killed)
                {
                    if (p_input[i].GetButtonDown("Action"))
                    {
                        fire.PlayOneShot(shootsound);
                        StartCoroutine(Example(i));
                        if ((Math.Abs(obj_tomato.transform.position.x - p_aims[i].transform.position.x) < 1 && Math.Abs(obj_tomato.transform.position.y - p_aims[i].transform.position.y) < 1) && (p_aims[i].transform.position.y > -4) && (p_aims[i].transform.position.x <7 || p_aims[i].transform.position.x> -7))
                        {
                            StartCoroutine(score(i));
                        }
                    }
                }
            }
        }

        else
        {
            //Play winner
            int pMax = p_points[0];
            gc.roundList[gc.currentRound - 1].winner = 0;
            for (int i = 0; i < 4; i++)
            {
                if (p_points[i] > pMax)
                {
                    pMax = p_points[i];
                    gc.roundList[gc.currentRound - 1].winner = i;
                }
            }
            if (end)
            {
                StartCoroutine(EndGame());
                end = false;
            }
        }
    }