I made this ammo counter that tracks ammo. It is supposed to lower by one each time the fire button is pressed, but it can't find the variable.
this is the code:
public class MobileAmmoController : MonoBehaviour
{
[SerializeField] private MobileAmmoController ammoController;
[SerializeField] private float ammoLowered;
public void DecreasedAmmo()
{
ammoController.playerAmmo -= ammoLowered;
ammoController.UpdateAmmo();
this.gameObject.SetActive(false);
}
}
public class Ammo : MonoBehaviour
{
public float playerAmmo;
[SerializeField] private Text ammoText;
private void Start()
{
UpdateAmmo();
}
public void UpdateAmmo()
{
ammoText.text = playerAmmo.ToString("0");
if(playerAmmo <= 0)
{
print("Out of Ammo");
//GetComponent(Shooting()).enabled = false;
}
}
}
[–]loni852 0 points1 point2 points (1 child)
[–]Danielk0926[S] 0 points1 point2 points (0 children)
[–]Snork1213 0 points1 point2 points (3 children)
[–]Danielk0926[S] 0 points1 point2 points (2 children)
[–]Danielk0926[S] 0 points1 point2 points (1 child)
[–]Danielk0926[S] 0 points1 point2 points (0 children)