Namespace error?

I’m trying to print to the GUI the number of bullets remaining in the clip of a MAC10, but it’s having problems. It looks something like this,

using UnityEngine;
using System.Collections;

public class ClipBehavior : MonoBehaviour {

    public int BulletsRemainingInClip = 30;

    void GUIUpdate(){
        if (BulletsRemainingInClip >= 30){
            GUILayout.Label(BulletsFloat);
        }else{
            GUILayout.Label(BulletsFloat + "

[R] Reload");
}
if (BulletFired){
BulletsRemainingInClip–;
}
}

    void OnGUI(){
        GameObject MAC10Slide = GameObject.FindGameObjectWithTag("Slide");
        public bool BulletFired = MAC10Slide.GetComponent<SlideMovement>().BulletFired;
        public string BulletsFloat = BulletsRemainingInClip.ToString();
        void GUIUpdate();
    }

    void Update(){
        OnGUI();
    }
}

and the three errors it gives me are somewhat confusing.

  1. Curly brace expected at the end of this line for some reason:

    GameObject MAC10Slide = GameObject.FindGameObjectWithTag(“Slide”);

Why would a curly brace go here? The function definition doesn’t end for three more lines.

  1. At the beginning of the void Update(){} line, “A namespace does not directly contain such members as fields or methods”. This has me stumped. For one thing, this isn’t a namespace, it’s a class. For another, even if it were a namespace, the reader had no problem with the functions above it!

  2. If I include the closing curly brace for MonoBehaviour{} (i.e, the critical one), it tells me “Type or namespace definition, or end-of-file expected”. Otherwise it’s fine.

After some deliberation, I’m changing my answer… Here is a suggestion as to what your code MIGHT look like, but you may find some issues depending on how you’re trying to use it.

using UnityEngine;
using System.Collections;

public class ClipBehavior : MonoBehaviour {
	
	public int BulletsRemainingInClip = 30;

	public bool BulletFired;   //must be declared up here for all functions below to access it.
	public string BulletsFloat;  //must be declared up here for all functions below to access it.

	GameObject MAC10Slide;  //must be declared up here for all functions below to access it.

	void Start(){
		MAC10Slide = GameObject.FindGameObjectWithTag("Slide");  //You want to place a GameObject.Find type function where it is only called once (usually). Calling this every frame will slow down your performance.
	}

	void GUIUpdate(){
		BulletFired = MAC10Slide.GetComponent<SlideMovement>().BulletFired;
		BulletsFloat = BulletsRemainingInClip.ToString();

		if (BulletsRemainingInClip >= 30){
			GUILayout.Label(BulletsFloat);
		}else{
			GUILayout.Label(BulletsFloat + "

[R] Reload");
}
if (BulletFired){
BulletsRemainingInClip–;
}
}

	void OnGUI(){
		BulletFired = MAC10Slide.GetComponent<SlideMovement>().BulletFired;  //Shouldn't call "Get Component" every frame either.  No reason to have this in OnGUI, you aren't writing anything on the GUI layer by doing this.
		BulletsFloat = BulletsRemainingInClip.ToString();  //no reason to have this in OnGUI
		GUIUpdate();
	}
	
	void Update(){
		OnGUI();  // don't need to call OnGUI in update, it is called every frame automatically.
	}
}

I’ll keep an eye on this post, I can help you write this script but I think we may be a few renditions away from achieving exactly what you’re getting at.