Why isn't my C# code sending updates to my text scoreboard?
This is my first game and for some of it I have followed tutorials. However I cannot seem to figure out why my collisions aren't getting sent to my scoreboard. Would someone be able to explain what im doing wrong and help me correct it?
using UnityEngine; using UnityEngine.UI;
public class Score : MonoBehaviour {
int score; //player score
public Text scoreText;
// start
void Start()
{
score = 0; //reset score
SetscoreText();
}
// end
void OnCollisionEnter(Collision collisioninfo)
{
if (collisioninfo.collider.tag == "Pins")
{
score += 10;
}
}
public void Update()
{
}
public void SetscoreText()
{
GameObject.Find("GameScore").GetComponent<Text>().text = "Score: " + score;
}
}
Comment
Answer by Vega4Life · Dec 19, 2018 at 04:33 PM
Set your score text when you add points.
void OnCollisionEnter(Collision collisioninfo)
{
if (collisioninfo.collider.tag == "Pins")
{
score += 10;
SetscoreText(); // ADD THIS
}
}
Your answer

Follow this Question
Related Questions
How to have a scoreboard system through multiple objects? 0 Answers
C# allowing the Player to name themselves and using it later in text 1 Answer
How can i restart a script on collision ? 1 Answer
Display Hit Text On Collition 0 Answers
Collision script doesnt work,OnCollisonEnter2D does not work if it collides with the enemy 2 Answers