Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[Roll a ball] Error error CS1061 with TextMeshProUGUI

Discussion in 'Getting Started' started by Selon-scrat, Sep 10, 2020.

  1. Selon-scrat

    Selon-scrat

    Joined:
    Sep 9, 2020
    Posts:
    1
    Hi,

    I'm a beginner in Unity and i've followed the Roll a ball tutorial to get started.

    I got an error at the 7.
    3.Display the count value section that saies :

    Assets\Scripts\PlayerController.cs(58,19): error CS1061: 'TextMeshProUGUI' does not contain a definition for 'Text' and no accessible extension method 'Text' accepting a first argument of type 'TextMeshProUGUI' could be found (are you missing a using directive or an assembly reference?)



    I checked my script, and it seems okay to me. I've followed every steps and i tried several solutions (changing things in the code, reinstall TMPro, install the extra TPro package, restart Unity, the computer...) i could find without making any progress.

    Does anyone have an idea to debug this error ?

    Thanks !

    My full script :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Collections.Specialized;
    4. using UnityEngine;
    5. using UnityEngine.InputSystem;
    6. using TMPro;
    7.  
    8.  
    9. public class PlayerController : MonoBehaviour
    10. {
    11.  
    12.     public float speed = 0;
    13.     public TextMeshProUGUI countText;
    14.     private Rigidbody rb;
    15.     private int count;
    16.     private float movementX;
    17.     private float movementY;
    18.  
    19.     // Start is called before the first frame update
    20.     void Start()
    21.     {
    22.         rb = GetComponent<Rigidbody>();
    23.         count = 0;
    24.  
    25.         SetCountText();
    26.     }
    27.  
    28.     void OnMove(InputValue movementValue)
    29.     {
    30.         Vector2 movementVector = movementValue.Get<Vector2>();
    31.  
    32.         movementX = movementVector.x;
    33.         movementY = movementVector.y;
    34.     }
    35.  
    36.  
    37.     void FixedUpdate()
    38.     {
    39.         Vector3 movement = new Vector3(movementX, 0.0f, movementY);
    40.  
    41.         rb.AddForce(movement * speed);
    42.     }
    43.  
    44.     private void OnTriggerEnter(Collider other)
    45.     {
    46.         if (other.gameObject.CompareTag("PickUp"))
    47.         {
    48.             other.gameObject.SetActive(false);
    49.             count = count + 1;
    50.  
    51.             SetCountText();
    52.         }
    53.        
    54.     }
    55.  
    56.     void SetCountText()
    57.     {
    58.         countText.Text = "Count: " + count.ToString();
    59.     }
    60. }
    61.  

     
  2. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481
    Tutorial time 2:32 to 2:58

    countText.text = "Count: " + count.ToString();
     
  3. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,509
    To expand upon @Valjuin's answer a bit, here's the code you have:

    Code (CSharp):
    1. countText.Text = "Count: " + count.ToString();
    and here's the code from the tutorial:

    Code (CSharp):
    1. countText.text = "Count: " + count.ToString();
    Do you see the difference? Capitalization matters in code, so the properties "Text" and "text" are not the same thing (in this case, "Text" doesn't exist, while "text" does.
     
    Valjuin likes this.