Quantcast
Channel: Questions in topic: "protection"
Viewing all articles
Browse latest Browse all 107

Can't access variable due to its protection level?

$
0
0
I know this means public versus private in most cases however, I do not see the issue here. This is a script to determine the appropriate "Classification" depending on the time and connections made. There are 4 possible ranks. From high to low, Legendary, Epic, Excellent, and Good. Each of these have a "goal" time and connections made. For example, to achieve Legendary. You need to make 10 connections, in under 12 seconds. And to achieve Epic, you must make 8 connections in 15 seconds. However, if you make 10 connections, in 13 seconds.. that is no longer qualified for Legendary since it took you too long. So you will drop down a class, to Epic. The goal is to get the most connections in the least amount of time. If the connections made and time qualify lower than Excellent, it will give you Good by default. Here is the script that I have, It seems to be working but I can't test it until I fix this error. LevelExit.CombinedScore.scoreName' is inaccessible due to its protection level. using UnityEngine; using System.Collections; using System.Collections.Generic; public class LevelExit : MonoBehaviour { public float padding; public GUIStyle myStyle; public string classification = ""; public int connections = 0; public float time = 0.0f; void Awake() { GameObject levelIntro = GameObject.Find("Level Introduction"); LevelIntroduction levelIntroScript = levelIntro.GetComponent(); int curConnections = GameLogic.getTotalConnections(); float curTime = GameLogic.getTotalTime(); CombinedScore playerScore = new CombinedScore("Player", curConnections, curTime); /// Here we initialize all the score values. CombinedScore legendaryScore = new CombinedScore("Legendary", levelIntroScript.LegendConnect, levelIntroScript.LegendTime); CombinedScore epicScore = new CombinedScore("Epic", levelIntroScript.EpicConnect, levelIntroScript.EpicTime); CombinedScore excellentScore = new CombinedScore("Excellent", levelIntroScript.ExcellentConnect, levelIntroScript.ExcellentTime); CombinedScore goodScore = new CombinedScore("Good", levelIntroScript.GoodConnect, levelIntroScript.GoodTime); /// Now put them all in a list, in order List referenceScoresFromHighToLow = new List() { legendaryScore, epicScore, excellentScore, goodScore }; /// Then pass in the player's score along with the list, so it can compare them classification = GetScoreClassification(playerScore, referenceScoresFromHighToLow); } public struct CombinedScore { int connections; float time; string scoreName; public CombinedScore(string name, int conns, float t) { scoreName = name; connections = conns; time = t; } } string GetScoreClassification(CombinedScore playerScore, List referenceScoresFromHighToLow) { foreach (CombinedScore score in referenceScoresFromHighToLow) { if (isBetterScore(playerScore, score)) { /// If it is a better score it returns the value, breaking out of the loop early. return score.scoreName; } } /// The value if it doesn't beat any of the reference scores return "Terrible"; } bool isBetterScore(CombinedScore playerScore, CombinedScore referenceScore) { if (playerScore.connections >= referenceScore.connections && playerScore.time <= referenceScore.time) { return true; } return false; } void OnGUI() { //Get the number of the current level. Since the range from 0, 1, 2+ //Add 1. int level = Application.loadedLevel + 1; GUI.Label(new Rect((Screen.width / 2) - (125 / 2), (Screen.height / 2) - (125 / 2) + padding + 25, 125, 25), "Level " + level.ToString(), myStyle); ///If you want to update this in real time, you can call GetScoreClassification right here! GUI.Label(new Rect((Screen.width / 2) - (125 / 2), (Screen.height / 2) - (125 / 2) + padding, 125, 25), "Classification: " + classification, myStyle); GUI.Label(new Rect((Screen.width / 2) - (125 / 2), (Screen.height / 2) - (125 / 2) + padding - 25, 125, 25), "Connections: " + GameLogic.getTotalConnections(), myStyle); GUI.Label(new Rect((Screen.width / 2) - (125 / 2), (Screen.height / 2) - (125 / 2) + padding - 50, 125, 25), "Time: " + (int)GameLogic.getTotalTime(), myStyle); } }

Viewing all articles
Browse latest Browse all 107

Trending Articles



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