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 nghebu · Feb 16, 2014 at 07:35 AM · menusimple fix

[Newbie] Simple Menu script c#

Hi! I'm a newbie in Unity and I want to make a simple menu script,i have watched/read some tutorials, but i don't understand what the problem is. Here is the code:

using UnityEngine; using System.Collections;

     public class Menu_Exit : MonoBehaviour
     {
     
         
         void OnMouseEnter()
         {
             renderer.material.color = Color.green;
         }
         
         void OnMouseExit()
         {
             renderer.material.color = Color.black;
         }
         
         void OnMouseDown()
         {
             Application.Quit();
         }
     }


When i start the application, nothing works. No color change, the application doesn't closes and I dont know why. Please help me Thanks!

Comment
Add comment
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

2 Replies

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

Answer by robertbu · Feb 16, 2014 at 07:39 AM

You can only change the color of an object if the shader supports it. Create a material with the standard 'Diffuse' shader (which than Default-Diffuse), and coloring changes will work. You may want to throw a directional light in the scene.

As for Application.Quit(), from the reference:

Quit is ignored in the editor or the web player.

You can put a Debug.Log() inside OnMouseDown() to verify it is getting called. Note the object you have this script attached to must have a collider before any of the three callback will work.

Comment
Add comment · Show 5 · 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 nghebu · Feb 16, 2014 at 11:51 AM 0
Share

I tried creating a material with the standard 'Diffuse' shader but the whole text become all black shape that I cannot see the text. Have I done something wrong?

avatar image robertbu · Feb 16, 2014 at 05:04 PM 0
Share

I'm guessing at your problem, but a diffuse shader needs a light. Throw a directional light into the scene:

 GameObject > Create Other > Directional Light

Note there are shaders that have a color that don't require lights. The 'Diffuse' was the first one I thought of that had a color parameter so you could test your code.

avatar image nghebu · Feb 17, 2014 at 02:20 PM 0
Share

the light didn't work out. Anyway, the script work just fine with the "Cube" object, however they dont work on the "3D text", what does it means?

avatar image robertbu · Feb 17, 2014 at 06:47 PM 0
Share

Ahhh, you are using a Text$$anonymous$$esh/3D Text object. You want to use the color property of the Text$$anonymous$$esh, not modify the material. So create a text mesh from scratch and back out of my material creation advice I game above. Assu$$anonymous$$g your script is on the same game object as the 3D Text, you can set the color by:

 gameObject.GetComponent<Text$$anonymous$$esh>().color = Color.black;
avatar image nghebu · Feb 19, 2014 at 11:02 AM 0
Share

oh now I did it! Thank you very much robertbu!!!!!

avatar image
-1

Answer by unimechanic · Feb 21, 2014 at 11:30 PM

[Question solved, adding this answer to remove it from the Unanswered list.]

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

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

19 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

Related Questions

Problem with Pause and Pause Menu Script 1 Answer

Simple Menu Script 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to emit a sound on specific collision. 1 Answer

Need a script 0 Answers


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