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 frank · Aug 26, 2010 at 05:23 PM · update

Question on Update()

Hi,all! I'm trying to make a window that could only be shown when the user both hover the mouse on the object and press the "return" button, but it seems there's something not right. Here is my code:

function OnMouseEnter () { MouseSwitch = true; print("Entered"); }

function OnMouseExit () { MouseSwitch = false; }

function Update () { if(MouseSwitch && (Input.GetKeyDown(KeyCode.Return))) { gameObject.GetComponent(menu).enabled = true; SwitchEnabled = true; } }

Can anybody give me a hand? THX!

I change the judge statement a little bit like shown below, this time the code works normally even though I dont know whats the different between this and the one before. And thanks, folks! here is the code:

function Update () {
if( MouseSwitch == true && Input.GetKey("return") ) {
        print("Correct!");
        SwitchEnabled = true;
        gameObject.GetComponent(menu).enabled = true;
}

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AliAzin · Aug 26, 2010 at 06:26 PM

OnMouseEnter() only works with colliders and GUI elements. you should add a collider component to your object.

Comment
Add comment · Show 3 · 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 frank · Aug 27, 2010 at 10:04 AM 0
Share

$$anonymous$$y object is a cube and has a collider already. "Entered" will be printed in the debug info when i hover my mouse on the object. The question is " if($$anonymous$$ouseSwitch && (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Return)))",when my mouse cursor is on the object and i press the return button, the code under this "if" wont be executed. I dont know why...

avatar image AliAzin · Aug 27, 2010 at 10:49 AM 0
Share

I tested your code and it worked correctly.

avatar image frank · Aug 27, 2010 at 03:00 PM 0
Share

theres nothing wrong with every single jugdement, but when im trying to add an "&&" between them, it seems that it cant judge correctly.

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

No one has followed this question yet.

Related Questions

How do I Instantiate a prefab to touch and still update a score? 1 Answer

Is Update() NOT linked with graphics refresh rate? 3 Answers

keep an if statement updating per frame in function Update 1 Answer

Refresh/Reload Model From Assets Folder Each Frame? 3 Answers

Unity won't start since updating ver 3.3 to 3.4 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