3D text as a button

Hello, sorry if this seems a little bit noobish, but I am just starting to begin using Unity. I currently have 3d text displayed on the scene, but I want to use this as a button. I’ve tried raycasting and I can’t seem to get it to work. Are there any alternatives to raycasting, or if not, how would I correctly use raycasting to create a button. Also, if possible, can you also state how you would make it so when you hover over the text, a light turns on, ect?

Put a collider on it and use OnMouseDown. Don’t bother with manually raycasting.

So to accomplish making 3d text as buttons you were very much on the right track with using ray casting, what you would want to do is create a ray from the camera that will detect your text

 #pragma strict

    var LightSource : Light;
    
      function Update()
      {
     
      var ray : Ray = camera.ScreenPointToRay (Input.mousePosition);
     
     var hit : RaycastHit;
     
    if(Physics.Raycast(ray, hit))
    {
     
    if(hit.collider.name == "InsertNameOfYourButtonHere")

    if(Input.GetMouseButton(0))
    {
     
    //Do what you want here
    
     
      }
     }
    }

This creates a ray from the camera to the mouse and if the ray hits your text (make sure it has a collider, doesn’t usually have one) and the Left mouse is pressed it will do what ever you assign it to do, now you said something about turning lights on and off, thats easy wants you have this code in, all you do is

     if(hit.collider.name == "InsertNameOfYourButtonHere")
       {
    
       LightSource.light.enabled = true;
       
       }else{

     LightSource.light.enabled = false;

}

Hope this helps!

Best of luck :slight_smile:

Okay, so just in case you decided not to follow my link above in the comment.
I have just created a package that you can download zip , unzip it, import package etc.

here it is below, it does not use raycasts, as there isnt really a need to do so.
It uses the unity process of material swapping on the text meshes using access to the OnMouse"" events automatically fired by Unity Engine along side the likes of Update, Start, Awake etc.

Soo… if you download this [24478-textmeshmouseovers.zip|24478]
Then follow these below steps.
1: Extract zip file contents(.package) to your desktop (or somewhere convenient)
2: Inside Unity, “Import Package-> Custom Package”
3: navigate to the freshly unzipped .package file and select it.
4:Make a “New Scene” and drag the “GUIControlObject” prefab on to your camera.
5: Press Play Button
6: move your mouse about and click on the 3 3D texts you see there.

7: Go to Code, see how that works, I have commented it.
8: Look at the text meshes and click on their respective fields in the inpsector to see the material attached to it etc.
9: rest easy, knowing today was a good day.
Take care bud
Gruffy