public void InfoImage_Onclick()
 {
     audioInfoImage = audioInfoImage.GetComponent <AudioSource>();
     audioInfoImage.PlayDelayed(0f);
     InfoImage_final.SetActive(false);
     star1.SetActive(false);
     star2.SetActive(false);
     star3.SetActive(false);
     Trophy.SetActive(false);
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        // Debug.Log(timmerLevel1);
        print(estadoJogo);
        //print("Position level 2" + player.transform.position + end_position);
        //print("Rotation level 2" + player.transform.rotation + end_rotation);
        switch (estadoJogo)
        {
        //set values end position and end rotation
        case GameState.INIT:
            //  estadoJogo = GameState.RUN;

            timmerLevel1 = 180f;
            end_position = new Vector3(-8.44f, 7.24f, 0.101f);
            end_rotation = transform.rotation;
            end_rotation.Set(0.0f, 0.0f, 0.4f, 0.9f);


            break;

        //update the timmer and detect if the win condition is met
        case GameState.RUN:
            //print("end-rotation" + player.transform.rotation);
            //print("position" + player.transform.position);


            timmerLevel1 -= Time.deltaTime;
            int min = Mathf.FloorToInt(timmerLevel1 / 60);
            int sec = Mathf.FloorToInt(timmerLevel1 % 60);
            TimmerLevel.GetComponent <TextMeshProUGUI>().text = (min.ToString("00") + ":" + sec.ToString("00"));
            TimmerLevel.SetActive(true);
            NameLevel.SetActive(true);


            if (timmerLevel1 <= 0)
            {
                estadoJogo = GameState.END_LOST;
            }



            if (WinCondition != 2)
            {
                if (Vector3.Distance(player.transform.position, end_position) < 0.5f)
                {
                    if (Quaternion.Angle(player.transform.rotation, end_rotation) < 0.5f)
                    {
                        WinCondition = 2;
                    }
                }
            }

            else
            {
                print("YOU WIN mivel 1");
                WinCondition = 0;
                InfoImage_final.SetActive(true);

                estadoJogo = GameState.END;
            }
            break;

        //if the player wins the level determines the number of stars given
        case GameState.END:

            playerController.StopCarOff();
            menu.SetActive(true);
            star1.SetActive(true);


            if (timmerLevel1 >= 180)
            {
                star2.SetActive(true);
            }

            if (timmerLevel1 >= 240)
            {
                star2.SetActive(true);
                star3.SetActive(true);
                trophy.SetActive(true);
            }

            audioCity.Pause();
            TimmerLevel.SetActive(false);
            NameLevel.SetActive(false);
            button_NextLevel.SetActive(true);
            button_Restart.SetActive(true);
            button_Start.SetActive(false);
            break;

        //when the players loses the game
        case GameState.END_LOST:
            playerController.StopCarOff();
            audioCity.Pause();
            TimmerLevel.SetActive(false);
            NameLevel.SetActive(false);
            menu.SetActive(true);
            button_NextLevel.SetActive(false);
            button_Restart.SetActive(true);
            button_Start.SetActive(false);
            break;
        }
    }
    // Update is called once per frame
    void Update()
    {
        // Debug.Log(timmerLevel1);
        print(estadoJogo);
        //print("Position level 2" + player.transform.position + end_position);
        // print("Rotation level 2" + player.transform.rotation + end_rotation);
        switch (estadoJogo)
        {
        //set values end position, end rotation and run the function StartGame()
        case GameState.INIT:
            //  estadoJogo = GameState.RUN;


            timmerLevel1 = 180f;
            end_position = new Vector3(-6.9f, 9.9f, 0.0f);
            end_rotation = transform.rotation;
            end_rotation.Set(0.0f, 0.0f, 0.4f, 0.9f);

            StartGame();



            break;

        case GameState.RUN:
            //print("end-rotation" + player.transform.rotation);
            //print("position" + player.transform.position);

            timmerLevel1 -= Time.deltaTime;
            int min = Mathf.FloorToInt(timmerLevel1 / 60);
            int sec = Mathf.FloorToInt(timmerLevel1 % 60);
            TimmerLevel.GetComponent <TextMeshProUGUI>().text = (min.ToString("00") + ":" + sec.ToString("00"));
            TimmerLevel.SetActive(true);
            NameLevel.SetActive(true);



            if (timmerLevel1 <= 0)
            {
                estadoJogo = GameState.END_LOST;
            }



            if (WinCondition != 2)
            {
                if (Vector3.Distance(player.transform.position, end_position) < 0.2f)
                {
                    if (Quaternion.Angle(player.transform.rotation, end_rotation) < 30f)
                    {
                        WinCondition = 2;
                    }
                }
            }

            else
            {
                print("YOU WIN nivel2 ****************************************************");
                WinCondition = 0;
                InfoImage_final.SetActive(true);

                estadoJogo = GameState.END;
            }
            break;

        case GameState.END:

            print("Veio aqui  ****************************************************");
            menu.SetActive(true);

            star1.SetActive(true);

            playerController.StopCarOff();
            if (timmerLevel1 >= 60)
            {
                star2.SetActive(true);
            }

            if (timmerLevel1 >= 120)
            {
                star2.SetActive(true);
                star3.SetActive(true);
                Trophy.SetActive(true);
            }


            TimmerLevel.SetActive(false);
            NameLevel.SetActive(false);
            button_NextLevel.SetActive(true);
            button_Restart.SetActive(true);
            button_Start.SetActive(false);
            break;

        case GameState.END_LOST:
            playerController.StopCarOff();
            TimmerLevel.SetActive(false);
            NameLevel.SetActive(false);
            menu.SetActive(true);
            button_NextLevel.SetActive(false);
            button_Restart.SetActive(true);
            button_Start.SetActive(false);
            break;
        }
    }