Here is my code but i get and object reference error.
private Shoot currentbullets;
void OnGUI()
{
guiText.alignment = TextAlignment.Left;
guiText.text = "Ammo = " + Shoot.currentbullets;
}
This is the other script
public class Shoot : MonoBehaviour
{
public Rigidbody projectile;
public float speed = 20;
public float currentbullets = 0;
public float totalbullets = 5;
// Use this for initialization
void Start ()
{
currentbullets = 5;
}
void Update ()
{
if (Input.GetButtonDown("Fire1"))
{
if(currentbullets > 0)
{
Rigidbody instantiatedProjectile = Instantiate(projectile,transform.position,transform.rotation)as Rigidbody;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
currentbullets--;
}
}
}
}