コード例 #1
0
    private void Update()
    {
        //setting car sound pitch
        carSound.pitch = GetComponent <Rigidbody2D>().velocity.magnitude / 20;

        //define items status variable
        itemsStatus = FindObjectOfType <ItemsStatus>();

        //activate game object of dimension button (boost button) when minimum a item collected
        if (itemsStatus.currentLevel == 1 && (itemsStatus.items1_1 || itemsStatus.items1_2))
        {
            boostButton.gameObject.SetActive(true);

            //add switching dimension button
            if (itemsStatus.items1_1 && itemsStatus.items1_2)
            {
                switchDimensionBtn.gameObject.SetActive(true);
                nextLevelNotif.gameObject.SetActive(true);
            }
        }
        else if (itemsStatus.currentLevel == 2 && (itemsStatus.items2_1 || itemsStatus.items2_2))
        {
            boostButton.gameObject.SetActive(true);

            //add switching dimension button
            if (itemsStatus.items2_1 && itemsStatus.items2_2)
            {
                switchDimensionBtn.gameObject.SetActive(true);
                nextLevelNotif.gameObject.SetActive(true);
            }
        }
        else if (itemsStatus.currentLevel == 3 && (itemsStatus.items3_1 || itemsStatus.items3_2))
        {
            boostButton.gameObject.SetActive(true);

            //add switching dimension button
            if (itemsStatus.items3_1 && itemsStatus.items3_2)
            {
                switchDimensionBtn.gameObject.SetActive(true);
                nextLevelNotif.gameObject.SetActive(true);
            }
        }

        //display count down timer to move to next map when minimum velocity requirement reached
        //if not, disactive the display.
        if (velocityAccepted)
        {
            timeLeft -= Time.deltaTime;
            timerDisplay.gameObject.SetActive(true);
            timerDisplay.text = timeLeft.ToString();
        }
        else
        {
            timeLeft = dimensionTimer;
            timerDisplay.gameObject.SetActive(false);
        }

        //do dimension travel if time left reached 0
        if (timeLeft < 0)
        {
            //when a map was not attended
            if (nextLevel == 2 && !map2WasAttended)
            {
                SceneManager.LoadScene("IntroMap" + nextLevel);
                FindObjectOfType <ItemsStatus>().currentLevel = nextLevel;
                map2WasAttended = true;
            }
            else if (nextLevel == 3 && !map3WasAttended)
            {
                SceneManager.LoadScene("IntroMap" + nextLevel);
                FindObjectOfType <ItemsStatus>().currentLevel = nextLevel;
                map3WasAttended = true;
            }
            else
            {
                SceneManager.LoadScene("Map" + nextLevel);
                FindObjectOfType <ItemsStatus>().currentLevel = nextLevel;
            }
        }
    }
コード例 #2
0
 private void Start()
 {
     itemsStatus = FindObjectOfType <ItemsStatus>();
 }