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
1
Question by Erin · Sep 22, 2010 at 04:33 PM · guimousekeyboard

Press Keyboard Instead Of Mouse

Been fighting with this for a couple of weeks now, thought I would ask one more time with updated code. I trigger a object by "walking" into which brings up a menu item. Instead of having to move the mouse (and camera) to press the button it would be nice to have the user press any key on the keyboard.

Any help would be appreciated.

var targetObj : GameObject;//drag your target into this slot in the editor var proximity : float = 3;//change trigger proximity here or in editor private var buttonOn : boolean; var customButton : GUIStyle;

function OnTriggerEnter (other : Collider) { buttonOn = true; GetComponent(MouseLook).enabled = false; }

function OnTriggerExit (other : Collider) { buttonOn = false; GetComponent(MouseLook).enabled = true; }

function OnGUI () {

if (buttonOn == true) {

     GUI.Box (Rect (450,0,400,125), "BUKU MALL NAVIGATION"); 


         if (GUI.Button (Rect (500,25,300,75), "Click Here To Go To The Main Courtyard")) 
         {
                  Application.LoadLevel(1);
         }

                     } 

}

function WindowFunction (windowID : int) { // Draw any Controls inside the window here }

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 sovalopivia · Sep 22, 2010 at 10:26 PM

You can just add the key check alongside the button press check, like so.

if (buttonOn == true) 
{
    GUI.Box (Rect (450,0,400,125), "BUKU MALL NAVIGATION"); 
    if (Input.anyKeyDown || GUI.Button (Rect (500,25,300,75), "Click Here To Go To The Main Courtyard")) 
    {
        Application.LoadLevel(1);
    }
} 

If this doesn't work I would assume that you haven't set buttonOn properly. Which could be because you dont have access to it in this script.

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 Erin · Sep 24, 2010 at 07:56 PM 0
Share

Worked like a charm! Thanks!

avatar image
0

Answer by alexnode · Sep 22, 2010 at 05:30 PM

adding in function update of your script something like

if..... Input.anyKey or Input.anyKeyDown ? haven't tried it ...

Edit... i think this could work ...

function Update () { if ((Input.anyKeyDown)&&(buttonOn==true)) {

buttonOn = false; Application.LoadLevel(1); } }

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 Erin · Sep 22, 2010 at 06:21 PM 0
Share

That is what I am playing with now, but I have not been able to get it to work as of yet.

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

Disable Mouse Input when OnGUI() 1 Answer

Ensuring Correct Call Order 0 Answers

Is there a way to combine the Update and OnGUI functions? 1 Answer

How to enable the mouse cursor in some areas? 1 Answer

How To Get Current Mouse Position and have a GUI Box on right clicked 2 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