using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Score : MonoBehaviour {
public Text ScoreText;
public GameObject Rings;
int score;
void Start () {
score = 0;
}
void Update () {
ScoreText.text = "Score: " + score;
}
void OnCollisionEnter2D (Collision2D col) {
if (col.gameObject.tag == “RocketTag”) {
score = score + 1;
}
}
}
2 In case of contact objects score does not count.
How to make that work? Thank you in advance!
public class Score : MonoBehaviour
{
public Text ScoreText;
public GameObject Rings;
int score;
void Start ()
{
score = 0;
ScoreText.text = "Score: 0";
}
void OnCollisionEnter2D (Collision2D col)
{
Debug.Log("My object "+gameObject.name+" collides with "+col.gameObject.name);
Debug.Log("The tag of "+col.name+"is "+col.gameObject.tag);
if (col.gameObject.tag == "RocketTag")
{
score++;
ScoreText.text = "Score: " + score;
}
}
}
Are you sure that the object with the Score script is actually the object that collides ? This should mean that this script is attached to the player.
What is the purpose of your Rings game object here ?