Two situations related to Debug.Log. I’m sure they are quite simple and I just don’t have the right knowledge.
- I want the debug log to tell me “Game Over” when my “lives” reach 0 or less.
When my “Lives” do reach 0, nothing shows up or happens
Here is the code:
public class GameManager : MonoBehaviour
{
//score count
private int score;
//connecting the UGUI score Canvas to the script
public TextMeshProUGUI scoreText;
//variable for lives
private int lives;
//connecting the UGUI life Canvas to the script
public TextMeshProUGUI lifeText;
// Start is called before the first frame update
void Start()
{
//score function
score = 0;
lives = -5;
UpdateScore(0);
LifeCount(0);
}
// Update is called once per frame
void Update()
{
//game over if lives below hit zero
if(lifeText.text <= "0")
{
Debug.Log("GAME OVER");
}
}
Situation #2
I want a message to appear saying “Damage Taken” when my player loses a “life” or his lives total is decreased. The object is being destroyed on collision as it should, though the message is not appearing. Any suggestions?
//method for destroying objects on collision
private void OnTriggerEnter(Collider other)
{
// enemies = GameObject.FindGameObjectsWithTag(“Animal”);
if (other.CompareTag("Player"))
{
//Destroys object that this script is attached to
Destroy(gameObject);
//decrease lives
gameManager.LifeCount(damage);
//life lost debuglog
Debug.Log("Damage taken");
,Two situations related to Debug.Log. I’m sure they are quite simple and I just don’t have the right knowledge.
- I want the debug log to tell me “Game Over” when my “lives” reach 0 or less.
When my “Lives” do reach 0, nothing shows up or happens
Here is the code:
public class GameManager : MonoBehaviour
{
//score count
private int score;
//connecting the UGUI score Canvas to the script
public TextMeshProUGUI scoreText;
//variable for lives
private int lives;
//connecting the UGUI life Canvas to the script
public TextMeshProUGUI lifeText;
// Start is called before the first frame update
void Start()
{
//score function
score = 0;
lives = -5;
UpdateScore(0);
LifeCount(0);
}
// Update is called once per frame
void Update()
{
//game over if lives below hit zero
if(lifeText.text <= "0")
{
Debug.Log("GAME OVER");
}
}
Situation #2
I want a message to appear saying “Damage Taken” when my player loses a “life” or his lives total is decreased. The object is being destroyed on collision as it should, though the message is not appearing. Any suggestions?
//method for destroying objects on collision
private void OnTriggerEnter(Collider other)
{
// enemies = GameObject.FindGameObjectsWithTag(“Animal”);
if (other.CompareTag("Player"))
{
//Destroys object that this script is attached to
Destroy(gameObject);
//decrease lives
gameManager.LifeCount(damage);
//life lost debuglog
Debug.Log("Damage taken");