- Home /
Question by
SquaredUnicycle · Jun 20, 2021 at 11:11 PM ·
collisionscoring
Making hit point scoring system
Game is when the player collides with an enemy object they score a point. I think my logic is correct but I have no idea why it is not working. I made a canvas with Text as a child and attached this script to it. It is giving me an error at the public Text scoreText line, saying ' The type or namespace name 'Text' could not be found (are you missing a using directive or an assembly reference?)'. Now I thought make a reference to the Text component would suffice but it is not working. Could someone please shed some light on this?
public class Score : MonoBehaviour
{
public GameObject player;
public Text scoreText;
void OnTriggerEnter()
{
if (player.collision.tag == "enemy")
{
scoreText.text += 1;
}
}
}
Comment
"Text" is UI object. You have to include "UnityEngine.UI" library.
Answer by eneIr · Jun 21, 2021 at 02:14 AM
Just add using UnityEngine.UI
to your script, it'll work.