コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        // Debug.Log(timeRemaining + "\n");
        if (timeRemaining > 0)
        {
            timeRemaining -= Time.deltaTime;
            text.text      = timeRemaining.ToString() + " s";

            // check if we can see the screen
            Vector3 screenPoint = Camera.main.WorldToViewportPoint(transform.position);
            bool    onScreen    = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
            if (onScreen)
            {
                text.gameObject.SetActive(true);
                text.transform.position = Camera.main.WorldToScreenPoint(transform.position + new Vector3(0, 0, -5));
            }
            else
            {
                text.gameObject.SetActive(false);
            }
        }
        else
        {
            Debug.Log("GameOver");
            levelManagement.setGameOver();
        }
    }