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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Error CS0118

Discussion in 'Scripting' started by Biallont, Dec 21, 2022.

  1. Biallont

    Biallont

    Joined:
    Sep 9, 2022
    Posts:
    2
    Assets\Infima Games\Low Poly Shooter Pack\Code\Demo\DisplayMaterialName.cs(43,13): error CS0118: 'TextMeshProUGUI' is a type but is used like a variable
    This is my code :

    // Copyright 2021, Infima Games. All Rights Reserved.

    using TMPro;
    using UnityEngine;

    namespace InfimaGames.LowPolyShooterPack
    {
    /// <summary>
    /// Displays a material's name in the world.
    /// </summary>
    public class DisplayMaterialName : MonoBehaviour
    {
    #region FIELDS SERIALIZED

    [Header("Settings")]

    [Tooltip("Mesh.")]
    [SerializeField]
    private Renderer mesh;

    [Tooltip("Text.")]
    [SerializeField]
    private TextMeshProUGUI materialText;

    #endregion

    #region FIELDS

    /// <summary>
    /// Material.
    /// </summary>
    private Material meshMaterial;

    #endregion

    #region UNITY

    private void Start()
    {
    //Get current material name from the mesh.
    string sharedMaterialName = mesh.sharedMaterial.name;
    //Output current material name to the UI text.
    TextMeshProUGUI = sharedMaterialName;
    }

    #endregion
    }
    }
     
  2. Biallont

    Biallont

    Joined:
    Sep 9, 2022
    Posts:
    2
    help me please
     
  3. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,596
    When posting code on the Scripting forum, make sure to use Code Tags so people can read your code easily. You can edit your post and add it.

    The error tells you what's wrong, you used a type like a variable. I don't even know what you're trying to do, so I can't help you unless you explain it.

    On another note, I'd suggest following some basic coding tutorials instead, C# has strict rules on how the syntax works, and if you don't know those you're not going to get anywhere.
     
    Antypodish and MaskedMouse like this.
  4. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    I pasted the OP into chatGPT verbatim, here's the generated reply:


     
    thelebaron, Antypodish and Voronoi like this.
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,903
    (Man, ChatGPT didn't even give OP a hard time about memorizing error codes. What is the world coming to?)
     
    thelebaron, stonstad, Rewaken and 5 others like this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    Well played, well played. :)