Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Moomius · Mar 29, 2014 at 12:30 PM · button

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gruffy · Mar 29, 2014 at 01:11 PM 1
Share

hey bud and Welcome to Unity Answers, With Text $$anonymous$$eshes, which i assume you are using, you may access the On$$anonymous$$ouseOver functionality.. Im going to link you to ansswer I once gave here for the same question, practically. I gave them a script that carries out what you are asking for, so follow that link bud. Changing around and interacting with text meshes answer

avatar image Owen-Reynolds · Mar 29, 2014 at 02:33 PM 1
Share

To raycast, follow any instructions for getting a mouse-position raycast to anything in the game world, like a cube. Raycasts go to invisible colliders (or triggers,) and don't care about what we see, like red cubes or 3D words. You're probably having trouble with that part. Once it works, just stick the 3DText there, and hide anything else.

But, yes, as Gruffy & Eric555 write, using On$$anonymous$$ouseDown is easier (but, you still have to figure out colliders. They tell the game where something counts as being.)

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Gruffy · Mar 29, 2014 at 02:40 PM

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 [zip][1] 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 [1]: /storage/temp/24478-textmeshmouseovers.zip


textmeshmouseovers.zip (68.4 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Moomius · Mar 30, 2014 at 03:40 AM 0
Share

Thank you so much for going that extra step to help me. Thanks for being so helpful :)

avatar image
2

Answer by Eric5h5 · Mar 29, 2014 at 01:46 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by _1 · Mar 29, 2014 at 01:25 PM

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 :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Moomius · Mar 30, 2014 at 03:39 AM 0
Share

Thanks for your help, I really appreciate it!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SetActive Button from another scene isn't working in build 0 Answers

Player will run 1 Answer

Gamepad press and release in Input Action - UI Buttons 1 Answer

how to make a button click able after a few seconds 2 Answers

Checking if Button is not pressed 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges