using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameDataDisplay : MonoBehaviour
{
public Text gameClockDisplay;
public Text boxesDroppedDisplay;
public Text gameScoreDisplay;
// Start is called before the first frame update
void Start()
{
}
void Update()
{
ShowTime();
BoxesDropped();
ShowScore();
}
void ShowTime()
{
// 3 Lines of code
//increment using Time.deltaTime
//define another variable to convert the totaltime to an integer - int time = (int) totalTime
//display text
}
void BoxesDropped()
{
int boxesDropped = UAVController.numberofMedicineBoxesDropped;
boxesDroppedDisplay.text = "number of medicine boxes dropped" + boxesDropped.ToString();
}
void ShowScore()
{
//a few lines of code here
}
To display the game time, you can use the Time.deltaTime property to keep track of the time that has elapsed since the game started. You can define a variable, totalTime, that keeps track of the total game time, and increment it each frame by the amount of time that has passed since the last frame. Then, you can convert totalTime to an integer and display it using the gameClockDisplay.text property.
Here is how you can implement this in the ShowTime() method:
void ShowTime()
{
//increment totalTime by the time that has passed since the last frame
totalTime += Time.deltaTime;
//convert totalTime to an integer
int time = (int) totalTime;
//display the time on the screen
gameClockDisplay.text = "Time: " + time.ToString();
}
To display the score, you can define a score variable and increment it whenever a certain in-game event occurs (for example, when a box is dropped). Then, you can display the score on the screen using the gameScoreDisplay.text property.
Here is how you can implement this in the ShowScore() method:
void ShowScore()
{
//increment score whenever a box is dropped
score += 10;
//display the score on the screen
gameScoreDisplay.text = "Score: " + score.ToString();
}
Note: The exact implementation of the ShowScore() method will depend on how your game works and what events you want to track to increment the score. The above code is just an example of how you can display the score on the screen.