Question by
tyranpro557 · Aug 03, 2016 at 04:53 PM ·
moneymoneysystem
error CS0116: A namespace can only contain types and namespace declarations C#. Whats wrong here?
i got this Error "error CS0116: A namespace can only contain types and namespace declarations"
the errors are at (19,17) and (24,17).
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class playerMoney : MonoBehaviour {
public int money;
public Text moneyText;
// Use this for initialization
void Start () {
money = 10;
moneyText.text = money.ToString;
}
// Update is called once per frame
void Update () {
}
}
public void addMoney (int moneyToAdd)
{
money += moneyToAdd;
moneyText.text = money.ToString;
}
public void subtractMoney (int moneyToSubtract) {
if (money - moneyToSubtract < 0) {
Debug.Log("Not EnoughMoney!");
} else {
money = moneyToSubtract;
moneyText.text = money.ToString;
}
}
}
Where did i done goof?
Comment
Best Answer
Answer by Landern · Aug 03, 2016 at 05:28 PM
You're curly brace usage was closing the class definition then you started defining more methods outside of the class.
Here is a reformatted and corrected class definition for you:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class playerMoney : MonoBehaviour
{
public int money;
public Text moneyText;
// Use this for initialization
void Start ()
{
money = 10;
moneyText.text = money.ToString;
}
// Update is called once per frame
void Update ()
{
}
public void addMoney (int moneyToAdd)
{
money += moneyToAdd;
moneyText.text = money.ToString;
}
public void subtractMoney (int moneyToSubtract)
{
if (money - moneyToSubtract < 0)
{
Debug.Log("Not EnoughMoney!");
}
else
{
money = moneyToSubtract;
moneyText.text = money.ToString;
}
}
}
Your answer
Follow this Question
Related Questions
money system in c# 0 Answers
Money not being added. 0 Answers
I need to fix a problem where my money resets when i continue to the next level 0 Answers
unity ads paying very low money with very less eCPM 0 Answers