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 sdgd · Feb 11, 2013 at 08:06 PM · c#functionevent-handlingmono-behaviour

how to call event function for keys mono-behaviour C#

  1. I'm trying to make an event that won't be called every frame but ONLY when event happens is it possible? if it's impossible

  2. how to call input so I verify in Update if correct thing was pressed (Forward is dinamic string (it changes dependent on the controlls user set it up)) if it's impossible

  3. is it really the least efficient way calling 60 or more controlls per frame just to walk forward?

  4. and if I have OnGUI () {} does it take more process?

    public string Forward = "W"; void OnKeyDown () { Debug.Log("ehgauebw"); }

    void Update () { if (Input.GetKey().ToString == Forward) { Debug.Log("ehgauebw"); } }

    void OnGUI (){ if (Event.current.keyCode.ToString() == Forward){ Debug.Log("sdeiflgh"); } }

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
Best Answer

Answer by Loius · Feb 11, 2013 at 08:14 PM

Check the Scripting Reference. GetKey takes a string or KeyCode argument, Event.current.keyCode is a KeyCode, so you should store your control as a KeyCode.

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 sdgd · Feb 11, 2013 at 08:17 PM 0
Share

ah now I get what you mean I'll try

and how do I fetch keycode scroll wheel than I was doing before like this

             // we catch $$anonymous$$ouseWheel Forward/Backward
             if (e.delta.ToString() == "(0.0, -3.0)"){
                 $$anonymous$$eys = "scroll Wheel Forward";
                 DontTurnOffToggle = false;
             }
             else if (e.delta.ToString() == "(0.0, 3.0)"){
                 $$anonymous$$eys = "scroll Wheel Backward";
                 DontTurnOffToggle = false;
             }




and than a function key can't be found Print screen

asd is $$anonymous$$eyCode in structure Bind$$anonymous$$ey

         if (Input.Get$$anonymous$$ey(bind$$anonymous$$ey.asd)){
             Debug.Log("ldjkas");
         }

if I set it to any different char I find it if to print screen that can be fetched only with event than I don't find 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

10 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

Related Questions

how to put in function any variables? like object? 2 Answers

Button not executing function. C# 3 Answers

is it possible to pass functions through functions? 2 Answers

How do I "trickle" a function's effect over n seconds? 2 Answers

Srcipting: how retrun struct in function , C#? 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