- Home /
Show Score While Holding 'TAB' Using GUI Text Through Script
Hi there guys, i'm having an issue both on researching and coding a stats page that gets displayed while holding 'TAB', I have a panel with Scripted GUIText that gets displayed while holding tab, but i am wondering how i can attach GUI texts to that panel? So that whatever the native resolution, it will stay attached to that panel, I need a way of changing the stats through code, so it cant be as simple as using UI text due to as far as i know UI Text cannot be modified through script. below is a video the may be more clear in what i am trying to achieve.
Code Below to show where i am at.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScoreSys : MonoBehaviour {
//Reqs
public GameObject stats;
//Player Stats
public float gameMoney = 0;
public float gameScore = 0;
public float gameExp = 0;
public float currentMoney = 0;
public float currentScore = 0;
public float currentExp = 0;
public float currentLvl = 0;
public float currentPrestige = 0;
//Gun Stats
public float apcBulletsShot = 0;
public float apcBulletsHit = 0;
//Zombie Stats
public float zKills = 0;
public float zHeadKills = 0;
private GUIStyle guiStyle = new GUIStyle();
private void OnGUI()
{
guiStyle.fontSize = 15;
guiStyle.normal.textColor = Color.white;
GUI.contentColor = Color.white;
if (Input.GetButton("Stats"))
{
GUI.Label(new Rect(25, 490, 260, 100), "Score This Game:" + gameScore, guiStyle);
GUI.Label(new Rect(25, 470, 260, 100), "Money This Game:" + gameMoney, guiStyle);
GUI.Label(new Rect(25, 450, 260, 100), "Exp This Game:" + gameExp, guiStyle);
}
}
// Use this for initialization
void Start () {
stats.SetActive(false);
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetButton("Stats"))
{
stats.SetActive(true);
}
else
{
stats.SetActive(false);
}
}
}
Your answer
Follow this Question
Related Questions
Can't increase my score after OnTriggerEnter occurs. 1 Answer
Help With Score Controller - Can You Only Have One? 1 Answer
INCREASE SCORE MORE AND MORE? 1 Answer
New score each level 1 Answer