} expected Type or namespace definition, or end-of-file expected, Basic Clicker
I'm making a basic clicker game to practice my skills in Unity and I've came across an error in mt script and I'm not sure what is causing it, my brackets do seem fine though. If you know whats wrong please answer, I feel it's such a simple thing I'm missing.
using UnityEngine;
using System.Collections;
public class BtnMng : MonoBehaviour {
public UnityEngine.UI.Text MoneyDisplay;
public int money = 0;
public int moneyeachclick = 1;
public int moneypersecond = 0;
// Update is called once per frame
void Update () {
MoneyDisplay.text = "Money: " + money;
public void Click() {
money = money + moneyeachclick;
}
}
}
Answer by Arcana96 · Oct 12, 2016 at 11:20 PM
Your Update() method seems to missing a curly brace.
public class BtnMng : MonoBehaviour {
public UnityEngine.UI.Text MoneyDisplay;
public int money = 0;
public int moneyeachclick = 1;
public int moneypersecond = 0;
// Update is called once per frame
void Update () {
MoneyDisplay.text = "Money: " + money;
}
public void Click() {
money = money + moneyeachclick;
}
}
Your code should look like that.
Yes but according to your code you've tried to define public void Click() inside of update. You can't do that. Each method has to be its own thing and Update counts as a method.
You define public void Click outside of the update function and call it within the Update function by calling it's name like Click();
For example:
void Update() { Click(); }
Your answer
Follow this Question
Related Questions
Code Help Needed. Anti-Time Cheat System Not Working !!! 0 Answers
Return key triggering a button OnClick? 1 Answer
Where can I learn C# 3 Answers