How can I make the text in text object do as button ?

hello. How can I make the text in text object do as button ?

I am not able to understand but ill give you the solution for what I understood
If your text is a UI text mesh pro component
Right click on “canvas” in the hierarchy and click on add button, then position it where you want and add the wanted script with the wanted function, if you do not know how watch a yt tutorial.

If your text is ingame, for example elevator button, and is not a UI
use -
private void OnMouseDown()
{

}

The first one is if it is a UI and second one if it is a in - game model or sprite

Greetings, @ProgrammerYahia

Just to fill in a few details. If you have either a legacy Text object (Text Mesh) or a TextMeshPro object, you need to add a box collider to them to receive mouse interaction. If you’re working in 2D, use a Box Collider 2D instead. When you’ve done that, you can use the following code:

using UnityEngine;

public class TextAsButton : MonoBehaviour
{
    private void OnMouseDown()
    {
        print("You have clicked on the text");
    }
}

There are other interactions (OnMouseEnter, OnMouseOver etc). Check out the Monobehaviour documentation for more details.

As @Mr_Potato342 suggests, this is used for in-game text as a rule. Perhaps when you click on text in a book or a sign etc.

If you want a “real” button then you need to use the UI system and that’s slightly different depending on which version of Unity you are using. The latest versions use the Unity UI package and a button uses TextMeshPro for its text. The older, legacy button can then be found in the Legacy section. However, both work the same in principle. However, you then have to set up a public method and link that to the button in the Inspector. It might be worth watching a suitable tutorial video. Unity’s tutorial video on this topic is a little heavy handed and not completely up to date but might help.

Do come back if you need any more help.