i want to use the score script written by the Unity team for a game but Unity can not find the type or namespace name “Text”.
using UnityEngine;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
public static int score; // The player's score.
Text text; // Reference to the Text component.
//Text is red
void Awake ()
{
// Set up the reference.
text = GetComponent <Text> (); // Text is red
// Reset the score.
score = 0;
}
void Update ()
{
// Set the displayed text to be the word "Score" followed by the score value.
text.text = "Score: " + score; // secound "text" is red
}
}
I hope anyone knows what to do
ERROR message:
Assets/Scripts/Score.cs(9,9): error CS0246: The type or namespace name `Text’ could not be found. Are you missing a using directive or an assembly reference?
new script for displaying the score and a function to add points:
using UnityEngine;
using UnityEngine.UI
using System.Collections;
public class ScoreManager : MonoBehaviour
{
public static int score = 0; // The player's score.
Text text; // Reference to the Text component. "Text" red
void Awake ()
{
// Set up the reference.
text = GetComponent <Text> (); // "Text" red
// Reset the score.
score = 0;
}
void Update ()
{
// Set the displayed text to be the word "Score" followed by the score value.
text.text = "Score: " + score; // secound text red
}
static public void AddPoint(){ //Use script to add point
score++;
}
}
i thought to add an other script to an collider to add the score, but it has a error too:
using UnityEngine;
using System.Collections;
public class ScoreAddingScript : MonoBehaviour {
void OnTriggerEnter2D(Collider2D collider) {
if (collider.tag == "Player") {
Score.AddPoint();
gameObject.SetActive(false);
}
}
}
Hello again! I have a small problem. What i have to do if “Score : 0” does not count?
ScoreAddingScript
using UnityEngine;
using System.Collections;
public class ScoreAddingScript : MonoBehaviour {
void OnTriggerEnter2D(Collider2D collider) {
if (collider.tag == "Player") {
ScoreManager.AddPoint();
//gameObject.SetActive(false);
Debug.LogError ("Activ ontrigger");
}
}
}
ScoreManager scirpt
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
public static int score = 0;// The player's score.
Text text; // Reference to the Text component.
void Awake ()
{
// Set up the reference.
text = GetComponent <Text> ();
// Reset the score.
score = 0;
}
void Update ()
{
// Set the displayed text to be the word "Score" followed by the score value.
text.text = "Score: " + score;
}
static public void AddPoint(){
score += score +1;
Debug.LogError ("adding Points");
}
}
Everything is working except displaying the Score with the text UI.