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
4
Question by DaveA · Feb 19, 2011 at 12:21 AM · inputeventvirtual

Can an Input event be 'faked' with a script?

You know how you can use the Input Manager to define an event like "Jump" which the user can assign to a key? Is there a way to then programmatically create a "Jump" event? I know I could call the appropriate functions directly, but if these events are handled in several script or ones I'd rather not muck with, it seems like faking events might be cleaner.

Specifically, I want to make some on-screen buttons that mimic keyboard buttons, so pressing the mouse over the on-screen 'left arrow' key would do the same thing as pressing the actual left arrow key.

Comment
Add comment · Show 1
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 · May 04, 2011 at 12:48 PM 0
Share

Dave, did you ever figure out a way to do this? In one gamestate, one script is intentionally ignoring input, but I wish to (occasionally) fake input that's specific to what's actually been pressed. If this is too obscure, I may just post a new question...

1 Reply

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

Answer by Eric5h5 · Feb 19, 2011 at 01:09 AM

Just abstract it:

function Update () { if (Jump()) { // do jumping } }

private var doJump = false;

function Jump () : boolean { if (Input.GetButtonDown("Jump")) { return true; } if (doJump) { doJump = false; return true; } return false; }

function DoJump () { doJump = true; }

Then call DoJump when an on-screen jump button is clicked or when you want to "fake" it. If you have jump input handled in more than one place, always call the Jump function instead of checking input directly.

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 DaveA · Feb 23, 2011 at 02:55 AM 0
Share

A bit more convoluted than I'd hoped, but it works, thanks

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

Why is this script showing all keycodes except shift? 2 Answers

replace Input.GetKey for mobile input 1 Answer

EventType.MouseDrag not working in WebPlayer 0 Answers

detecting touch on gameObject 1 Answer

Get a script to the object with the press of a button 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