Game Development Reference
In-Depth Information
public float starting_time : This variable will store the time
when the timer should start before the level ends. Let's remember to
set this to 120 seconds.
private float t : This variable will be used to store the current
elapsed time.
public boolean timeElapsed = false : This Boolean variable
will store whether or not this timer has reached zero at this time
through the level.
These variables can be declared in the following manner:
public GameObject failPopup;
public float starting_time;
private float t;
public boolean timeElapsed = false;
4. Inside the update() loop, we subtract the actual amount of time elapsed
from t each time update() is called as shown in the following code:
t -= Time.deltaTime;
5. Once the time has elapsed, we tell the camera to look up and then show
the fail pop up by setting its enabled flag to true . We set the local
timeElapsed Boolean to true as well so that this response cannot show
multiple times in a row accidentally:
if (t < 0.0f)
{
GameObject camObj =
Camera.main.gameObject;
if (camObj) {
camObj.GetComponent<GameCam>().LookUp();
failPopup.SetActive(true);
timeElapsed = true; }
}
Search WWH ::




Custom Search