Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

`UnityEngine.UI.Text' does not contain a definition for `Text'

Discussion in 'Editor & General Support' started by RyanMcDonnell, May 30, 2017.

  1. RyanMcDonnell

    RyanMcDonnell

    Joined:
    May 30, 2017
    Posts:
    2
    Context: I am making a 2d platforming game ive created a canvas it has a Text script attached, it shows in game. The piece of code bellow cant find the Text type used by the canvas . (im new to this stuff its assignment work an this has stopped me) Unity cant find the 'definition for Text type' even though i am using UnityEngine.UI i don't know what to do.


    (ScoreManager.cs)
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class ScoreManager : MonoBehaviour {

    public Text scoreText;

    public float scoreCount;




    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
    scoreText.Text = "Food: " + scoreCount;
    }
    }


    (Pickup.cs)

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Pickup : MonoBehaviour {

    public int scoreToGive;

    private ScoreManager theScoreManager;

    void Start () {
    theScoreManager = FindObjectOfType<ScoreManager>();
    }

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

    void OnTriggerEnter2D(Collider2D other)
    {
    if (other.gameObject.name == "CharacterRobotBoy")
    {
    theScoreManager.scoreCount += scoreToGive;
    Destroy(gameObject);
    }
    }
    }
     
  2. Scabbage

    Scabbage

    Joined:
    Dec 11, 2014
    Posts:
    268
    Please use code tags when posting code.
    Code (csharp):
    1. // Correct use is:
    2. scoreText.text
    3. // Not:
    4. scoreText.Text
    IntelliSense is your friend. MonoDevelop and Visual Studio show possible matches as you type, in the case of VS it's activated with ctrl + space.
     
    Last edited: May 31, 2017
    calummulveen likes this.
  3. RyanMcDonnell

    RyanMcDonnell

    Joined:
    May 30, 2017
    Posts:
    2
    thanks dude, i was using unity collabe and my friend said it was working and it turned out it was my client and so reinstalled and it worked so i dont know :)
     
    Tomuteki likes this.
  4. Scabbage

    Scabbage

    Joined:
    Dec 11, 2014
    Posts:
    268
    Well, that is bizzare. I've never used Collaborate, perhaps there was some error-correcting going on. Instances of Text don't have a "Text" field.
     
  5. cody01100011

    cody01100011

    Joined:
    May 21, 2020
    Posts:
    4