Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

UI elements not accessible due to protection level

$
0
0
I've been struggling with this error for a few days now and can't find a way out ... I've searched on the forum and found that this error should be caused by the property being private but in my case i switched everything to public and still no good. I've tried inserting constructors and whatnot , now I need your help please. Btw it's a clicker project I started to learn how to use Unity Main File----------------------------------------------------------------------------------------------------------- using UnityEngine; using System.Collections; public class InitScript : MonoBehaviour { public UnityEngine.UI.Text goldText, BonusInfoText, GPSText; public float gold = 0, GPC = 0, GPS = 0; public GPCUpgrade pioche = new GPCUpgrade(){name="Pioche",baseCost=100,cost=100,bonusPower=1, level=0}; public GPCUpgrade chariot = new GPCUpgrade(){name="Chariot",baseCost=100,cost=100,bonusPower=1, level=0}; public GPCUpgrade dynamite = new GPCUpgrade(){name="Dynamite",baseCost=100,cost=100,bonusPower=1, level=0}; //public GPSUpgrade mineurs = new GPSUpgrade("Mineur",15,15,0.1f,0); //public GPSUpgrade mineurs = new GPSUpgrade(){name="Mineur",baseCost=15,cost=15,bonusPower=0.1f, level=0}; void Start () { InvokeRepeating ("Tick", 1.0f, 1.0f); } void Update () { pioche.bonusPower = 0; goldText.text = "Gold\n" + Mathf.Floor(gold); BonusInfoText.text = "Gold par click : " + GPC+ "\nGold par seconde : " + GPS; } private void Tick(){ GPS = (Mathf.Round (GPS*10))/10; gold += GPS; } private void GoldClick(float gold, float GPC){ gold+= GPC; } private void GPCClick(float gold, float GPC){ } private void GPSClick(float gold, float GPS){ } } Class File ------------------------------------------------------------------------------------------------------ using UnityEngine; using System.Collections; public class GPSUpgrade : MonoBehaviour { public string nom = ""; public int baseCost = 0; public int cost = 0; public float bonusPower = 0; public int level = 0; public UnityEngine.UI.Button btn = new UnityEngine.UI.Button (); public UnityEngine.UI.Text GPSText=new UnityEngine.UI.Text(){text=nom + "\t\t\t LVL " + level + "\nCost : " + cost+ "gold \nGain ; "+ bonusPower + "GPS"}; /*public GPSUpgrade(){ string nom = ""; int baseCost = 0; int cost = 0; float bonusPower = 0; int level = 0; UnityEngine.UI.Button btn = new UnityEngine.UI.Button (); UnityEngine.UI.Text GPSText=new UnityEngine.UI.Text(){text=nom + "\t\t\t LVL " + level + "\nCost : " + cost+ "gold \nGain ; "+ bonusPower + "GPS"}; } public GPSUpgrade(string vnom,int vbaseCost, int vcost, float vbonusPower, int vlevel){ string nom = vnom; int baseCost = vbaseCost; int cost = vcost; float bonusPower = vbonusPower; int level = vlevel; UnityEngine.UI.Button btn = new UnityEngine.UI.Button (); UnityEngine.UI.Text GPSText=new UnityEngine.UI.Text(){text=nom + "\t\t\t LVL " + level + "\nCost : " + cost+ "gold \nGain ; "+ bonusPower + "GPS"}; } */ public void Clicked(float gold, float GPS){ if (gold >= cost) { gold -= cost; GPS += bonusPower; level++; cost = Mathf.FloorToInt(baseCost * Mathf.Pow(1.15f,level)); } } } ![alt text][1] [1]: /storage/temp/95649-capture.png

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>