Question by
BaneIG88 · Sep 16, 2020 at 07:57 PM ·
programming
How can I add the word Score along with the actual score to the text in-game?,How to add Score to the text in game.
I have managed to get the Score to print on-screen and update in game but cannot figure out how to put the word score before it.
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class SharkScript : MonoBehaviour {
int Score = 0;
public Text ScoreText;
public Text nameText;
// Use this for initialization
void Start ()
{ ScoreText.text ="Score: " + Score;
string myName = "Rathian";
Debug.Log(myName + "shark is attacking");
ScoreText.text = "Score : " + Score;
Debug.Log("Score =" + Score);
}
// Update is called once per frame
void Update ()
{
ScoreText.text = Score.ToString();
// move the shark according to the inputs
transform.Translate (Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0.0f);
}
void OnCollisionEnter2D (Collision2D otherObject)
{
Score = Score ++;
ScoreText.text = "score: " + ScoreText;
float score;
Debug.Log("Score =" + Score);
}
} ,So far I've only managed to get it to show the score 0,1 ,2 ect. in-game. I need it to show the word Score with the actual score, 0 but I cannot figure out how to get the word score up there with the actual score in game.
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class SharkScript : MonoBehaviour {
int Score = 0;
public Text ScoreText;
public Text nameText;
// Use this for initialization
void Start ()
{ ScoreText.text ="Score: " + Score;
string myName = "Rathian";
Debug.Log(myName + "shark is attacking");
ScoreText.text = "Score : " + Score;
Debug.Log("Score =" + Score);
}
// Update is called once per frame
void Update ()
{
ScoreText.text = Score.ToString();
// move the shark according to the inputs
transform.Translate (Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0.0f);
}
void OnCollisionEnter2D (Collision2D otherObject)
{
Score = Score ++;
ScoreText.text = "score: " + ScoreText;
float score;
Debug.Log("Score =" + Score);
}
}
Comment
Your answer