- Home /
Scoring help !
hello all
First I apologize for my bad English
Secondly I would like to know how I can do that when you collect 100 coins instead of displaying "Coins: 100" ... I want to show me something like "beginner". If I collected 200 coins "advanced" .... 300 "experienced"
Here is my script
using UnityEngine;
using System.Collections;
public class CoinsTotalShow : MonoBehaviour {
private int coins = 0;
public Texture2D coinIconTexture;
// Use this for initialization
void Start () {
coins = PlayerPrefs.GetInt("Coins", coins);
}
// Update is called once per frame
void Update () {
}
void FixedUpdate (){
PlayerPrefs.SetInt("Coins",coins);
}
void DisplayCoinsCount()
{
Rect coinIconRect = new Rect(10, 10, 32, 32);
GUI.DrawTexture(coinIconRect, coinIconTexture);
GUIStyle style = new GUIStyle();
style.fontSize = 30;
style.fontStyle = FontStyle.Bold;
style.normal.textColor = Color.yellow;
Rect labelRect = new Rect(coinIconRect.xMax, coinIconRect.y, 60, 32);
GUI.Label(labelRect, coins.ToString(), style);
}
void OnGUI()
{
DisplayCoinsCount();
}
}
Answer by Sir-Irk · Nov 17, 2014 at 04:03 PM
Edit: If you haven't used if() statements before then here is a video. Learning all the concepts on that page will help you solve the majority of problems in scripting.
Edit2: I've made the code closer to what you want. But please watch the videos as this is a very rudimentary programming problem.
I'm unsure of the specifics of what you want but this should get you started:
string skillLevel = coins.ToString() + " ";
if(coins >= 300){
skillLevel += "Experienced";
}
else if(coins >= 200){
skillLevel += "Advanced";
}
else if(coins >= 100){
skillLevel += "Beginner";
}
Rect labelRect = new Rect(coinIconRect.xMax, coinIconRect.y, 60, 32)
GUI.Label(labelRect, skillLevel, style);
Modify the if() logic however you need.
Sorry for delayed response. $$anonymous$$y comment keeps disappearing.
Can you post the new code so I can see how you implemented it? Also, do you mean that the label is showing no text? If so make sure coins goes above or equal to 100.
I've also edited my answer to include a video that should help you with if() statements.
Bit vague there Louis.
I believe Irk was illustrating the method rather than handing you some completed code
this should get you started
His method is a most useful one and is a simple answer to a simple problem.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I want my score to reset back to 0 but keep my highscore saved 3 Answers
Scoring System 3 Answers
Letter Ranking System, Checking Higher Rank 1 Answer
How to save score for survival time? 1 Answer