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.
-
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.
-
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! -
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.