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 Velketor · Mar 07, 2011 at 02:43 PM · guispeedruncharge

Speed vs Fatigue

I have a character that needs to fatigue as he runs, requiring the player to stop running in order for the fatigue meter to recharge.

How can I go about doing this? Do I need to make a special GUI or something? Please let me know, my scripting abilities are limited and I'm trying to learn. I would greatly appreciate it! Thank you!

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
1

Answer by Jesse Anders · Mar 07, 2011 at 02:59 PM

First, you need to separate the 'simulation' aspect from the 'UI' aspect (think 'model-view'). These are two separate problems, and trying to solve them at the same time will just lead to confusion.

The UI part is probably the easier of the two aspects of the problem. I don't know what you want to display exactly (a number representing the current 'fatigue' factor maybe?), but at its simplest, you can just use GUI.Label() or GUILayout.Label() to display a numerical value.

Tracking fatigue and responding accordingly is the trickier part. As is usually the case, there's more than one way it can be done, but here's how I'd probably proceed:

  • If the player is running, increase the fatigue factor, using Time.deltaTime to scale the increase rate
  • If the player is not running, decrease the fatigue factor (clamping at 0), using Time.deltaTime to scale the decrease rate
  • If the player is running and the fatigue factor reaches the maximum (assuming that's how you want it to work), disable running for the player until the fatigue factor has gone down by some amount
Comment
Add comment · 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
0

Answer by dissidently · Mar 07, 2011 at 03:03 PM

You'll need someone with real scripting skills, which I don't have. I can only give a theoretical answer.

You'll need a boolean variable that stores [player_is_running: TRUE/FALSE]

When [player_is_running = TRUE] you need a function that negatively impacts the players Fatigue (another variable) across the time that the player is running.

When [player_is_running = FALSE] you need to activate another function that impacts positively upon the Fatigue variable.

The above to can be tested for in an Update function upon the player character object, probably in a If, then, else loop.

Sorry I can't be of more help. Someone with real coding skills will likely be along shortly to shoot down my ideas and show you how it best be done.

Comment
Add comment · 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

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 to convert a string into a function in JS? 2 Answers

How to change speed of game in real time using GUI Slider? 1 Answer

Marquee.cs speeds up scrolling with keydown 1 Answer

Speed when you press the button 1 Answer

Changing Speed in Gameplay Affects GUI 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