Problem with "Text" library in Unity

0

The problem that I have now, is that in my game I want to make a points counter that is shown in a text on the screen, but when doing the script, I get the error:

  

(Type UnityEngine.UI.Text does not contain a definition for Text '   and no extension method Text 'of type UnityEngine.UI.Text' could be   found Are you missing an assembly reference?)

But when I include a using UnityEngine.UI.Text , I get this other error:

  

(A use directive can only be applied to namespaces but   UnityEngine.UI.Text 'denotes a type. Consider using a 'using static'   instead).

If you can help me, I would really appreciate it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public enum  GameState{Idle, Playing, Ended, Ready};//estados del juego

public class GameController : MonoBehaviour {

    [Range (0f, 0.20f)]//rango de velocidad dentro de unity
    public float parallaxSpeed = 0.02f;//velocidad inicial
    public float scaleTime = 6f;//cada sierta cantidad de tiempo dado
    public float scaleInc = .25f;//incrementar
    public RawImage fondo;
    public RawImage plataforma;
    public Text pointText;
    public GameObject uiIdel;
    public GameState gameState = GameState.Idle;//estado por defecto, parado
    public GameObject player;
    public GameObject enemyGenerator;

    private AudioSource musicPlayer;

    private int points = 0;


    // Use this for initialization
    void Start () {
        musicPlayer = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update () {

        bool userAction = Input.GetKeyDown("up") || Input.GetMouseButtonDown(0);

        //empieza el juego
        if (gameState == GameState.Idle && userAction){//teclado arriba o mouse izquierdo respectivamente
            gameState = GameState.Playing;//pasar de estado "Idle" a "Playing"
            uiIdel.SetActive(false);
            player.SendMessage("UpdateState", "PlayerRun");
            player.SendMessage("DustPlay");
            enemyGenerator.SendMessage("StartGenerator");
            musicPlayer.Play();
            InvokeRepeating("GameTimeScale", scaleTime, scaleTime);//cada 6 seg llama al scaletime, y luego se repetira cada 6 seg
        }

        //juego en marcha
        else if(gameState == GameState.Playing){
            Parallax();
        }
        //juego preparado para reiniciarce
        else if(gameState == GameState.Ready){
            if (userAction){
                RestartGame();
            }
        }
    }

    void Parallax(){
        float finalSpeed = parallaxSpeed * Time.deltaTime;//Adapta velocidad segun el ordenador
        fondo.uvRect = new Rect(fondo.uvRect.x + finalSpeed, 0f, 1f, 1f);//velocidad del fondo
        plataforma.uvRect = new Rect(plataforma.uvRect.x + finalSpeed * 4, 0f, 1f, 1f);//velocidad de la plataforma
    }

    public void RestartGame(){
        ResetTimeScale();
        SceneManager.LoadScene("principal");
    }

    void GameTimeScale(){
        Time.timeScale += scaleInc;//incrementa la velocidad dependiendo del tiempo dado anteriormente
        Debug.Log("Ritmo Incrementado: " + Time.timeScale.ToString());
    }

    public void ResetTimeScale(){
        CancelInvoke("GameTimeScale");
        Time.timeScale = 1f;
        Debug.Log("Ritmo Incrementado: " + Time.timeScale.ToString());
    }

    public void IncreasePoints(){
        pointText.Text = (++points).ToString();
    }
}

    
asked by Eduardo Herrera 01.08.2018 в 19:01
source

1 answer

2

If you want to modify the text of an object of class Text you must use the property text . Your problem is that you are using Text (with the capital T, which refers to the class Text ) instead of the property text in the following line:

public void IncreasePoints(){
   pointText.Text = (++points).ToString(); // <------
}

It would be enough to change the text property to lowercase:

pointText.text = (++points).ToString();
    
answered by 02.08.2018 / 12:15
source