- Home /
Scoring points problem
Hello everyone, I am new in Unity and I need your help. I am doing game almost same as on Image but I have got there 4 pick up objects with different shapes. I dont know how to count score,under every side of square I have placed empty game object with script attached.
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Triangel"))
{
Destroy(other.gameObject);
clipAudio.Play();
count = count + 1;
}
}
But when I picked up different object score has restarted. Here is my ScoreController which doesnt work. I have no idea what to do next. Please help me I will appreciate it.
public Text countText; public int count; public int Count1; public int Count2; public int Count3; public int Count4;
private void Start()
{
Count1= GameObject.Find("Triangels").GetComponent<TriangelsPickUp>().count1;
Count2 = GameObject.Find("Squares").GetComponent<SquaresPickUp>().count2;
Count3 = GameObject.Find("Circles").GetComponent<CirclesPickUp>().count3;
Count4 = GameObject.Find("Diamonts").GetComponent<DiamontsPickUp>().count4;
SetCountText();
count = 0;
}
private void Update()
{
count = Count1+Count2+Count3+Count4;
SetCountText();
}
void SetCountText()
{
countText.text = "Score: " + count.ToString();
}
Answer by shadowpuppet · Mar 28, 2017 at 07:21 PM
I'd like to help as I had the same issue a while back. But my game is 3D not 2D and I know nothing about 2d. My score is text on the HUD Canvas with a "score manager "script attached to it. this is the script I use on the scoretext
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
public static int score = 00;
void Awake ()
{
text = GetComponent <Text> ();
}
void Update ()
{
text.text = "Score: " + score;
}
}
and to add to the score on another gameObject
void OnTriggerEnter (Collider other) {
if(other.tag == "Grenade")
ScoreManager.score+=100;
}
}
Thanks a lot. It has solved my problem.I really appreciate it.@shadowpuppet
Your answer
Follow this Question
Related Questions
Multiple score counters instead of just one? 2 Answers
High score value remains constant in game over scene, even if player has scored higher. 1 Answer
Plz Help, Score/Kill counter and Enemy Movement 0 Answers
I want my score to reset back to 0 but keep my highscore saved 3 Answers
How to create a score manager script involving awarding points from multiple objects? 2 Answers