Hello
So I just started doing some coding on Unity (yes, I’m a complete noob). My codes looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ConsoleTest : MonoBehaviour
{
private int ammo = 5;
// Start is called before the first frame update
void Start()
{
//Debug.Log(“Inside the Start function”);
Debug.Log(“Game has started. Reading ammo as” + ammo);
//ammo = ammo - 1;
//Debug.Log(“Now reading ammo as” + ammo);
}
// Update is called once per frame
void Update()
{
//Debug.Log(“Inside the Update function”);
if (Input.GetMouseButtonDown(0))
{
//Debug.Log(“Reading LMB clicked”);
if (ammo > 0)
{
ammo = ammo - 1;
Debug.Log(“You have” + ammo + “bullets remaining”);
}
else if (ammo < 1)
{
Debug.Log(“Your gun is empty. Hit R to reload”);
}
}
}
}
Whenever I click my LMB, the amount of ammo will be decreased and reported to me through the console screen of Unity. But what I’m struggling with is I when my ammo was decreased to 1, I want Unity to report “I have 1 bullet remaining” instead of “You have 1 bullets remaining”. I tried changing if to if (ammo > 0 && ammo != 1) as well as adding else if (ammo == 1) but none have worked. So if there’s someone can help, I would be very appreciated. Thank you so much.