Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Rick 1 · May 03, 2010 at 06:47 PM · camerainputtimeuser

Looking for a script to call function if there is no user input for set amount of time.

Hi,

I'm new to unity and fairly new to programming in general.

My current problem is that I have a program which allows the user to toggle between different cameras. The user can control the cameras with the A,S,D,W keys plus the mouse itself to look around. What I'm looking for is a script that will keep checking whether there has been any user input, from the keys or mouse, and if there hasn't been, for example, 90 seconds call a function to revert back to the main menu.

Any advice on how best to accomplish this is much appreciated.

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

Answer by duck · May 03, 2010 at 07:09 PM

Something like this should do it. I'm using the GetAxis functions because - by default - WASD and the Arrow keys both map to the horizontal and vertical axes.

private var lastActivity = 0; var idleThreshold = 90;

function Start() { lastActivity = Time.time; }

function Update() {

 var h = Input.GetAxis("Horizontal");
 var v = Input.GetAxis("Vertical");
 var x = Input.GetAxis ("Mouse X");
 var y = Input.GetAxis ("Mouse Y");

 if ( h != 0 || v != 0 || x != 0 || y != 0 ) {
     lastActivity = Time.time;
 }

 if (Time.time > lastActivity + idleThreshold) {
     EscapeToMenu();
 }

}

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 Rick 1 · May 03, 2010 at 07:23 PM 0
Share

Works an absolute treat! Thanks a lot, Duck!

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

Stop Watch start when told 2 Answers

Instanced Prefabs won't face camera. 2 Answers

Inspection camera script problem 2 Answers

Aligning Camera to Object 2 Answers

Camera Script - RtS style, rotation issues 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