Hi, sorry if the title is poor.
I’m very new to programming and unity and absolutely terrible with terminology.
I am trying to create a simple idle like game with multiple buttons of different types to give a reward of money and exp.
Here’s some example of what i currently have:
public class BaseSkill : MonoBehaviour {
public double level = 1, exp , nextLevel = 10;
public GameObject building;
public Text materialText, xpRewardText, cashRewardText, timerText;
}
public class MiningSkill : BaseSkill {
double miningLvl = 1;
double miningExp;
double mineNextLevel = 15;
void Start ()
{
Setup ();
}
void Setup()
{
level = miningLvl;
exp = miningExp;
nextLevel = mineNextLevel;
//materialText = building.FindGameObjectWithTag ("Material").GetComponent<Text> (); //Not Working.
materialText = GameObject.FindGameObjectWithTag ("Material").GetComponent<Text> ();
xpRewardText = GameObject.FindGameObjectWithTag ("XpReward").GetComponent<Text> ();
cashRewardText = GameObject.FindGameObjectWithTag ("CashReward").GetComponent<Text> ();
timerText = GameObject.FindGameObjectWithTag ("Timer").GetComponent<Text> ();
}
}
I have a fishing skill which is basically the same.
I have the buildings; Mine and the Fishing Hut (from the image), They’re just duplicates of each other and their Text field tags are exactly the same.
What i would like to have is some way of differentiating these buttons from each other. This is where i’m finding it pretty hard to figure out, i thought it would be as simple as using:
materialText = building.FindGameObjectWithTag ("Material").GetComponent<Text> ();
And this is where my terrible knowledge of the terminology comes into play. I have only a very basic understanding of the Error code:
Assets/Scripts/New Folder/Skills/MiningSkill.cs(37,41): error CS0176: Static member `UnityEngine.GameObject.FindGameObjectWithTag(string)' cannot be accessed with an instance reference, qualify it with a type name instead infact i’m clueless, programming really makes me feel stupid. Does it mean, i cannot access GameObject building because it’s static and i’m trying to create a new instance reference of it ?
BASICALLY, i want to be able to create a GameObject (or something) which is equal to the game obj (or tag) each collection of buttons(buildings) are under, then i want to change their text fields independent of each other for every SkillClass i create(mining, fishing, carpentry).
I don’t know if this makes any sense to anyone because after 3 hours i think i’m overthinking everything, But any help will be greatly appreciated.
I can upload the whole project if needed, but it’s not pretty and most likely full of redundant code. ![]()
