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 soulblade · Sep 25, 2012 at 05:53 AM · javascripttimer

Sprinting script, timer?

hi everyone I am making a game and i want the player to be able to have a running timer to time sprinting and then after the timer has gone of to set the speed to crouch speed and regenerate the time will using crouch speed. thx for helping if you submit a anwser.

Comment
Add comment · Show 4
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 Fattie · Sep 25, 2012 at 07:29 AM 0
Share

You use Invoke(), InvokeRepeating() and InvokeCancel() for very easy timers in Unity3D. you can find 1000s of examples on here.

 Invoke( "changeToCrouchSpeed", 3.5 );

etc.

avatar image soulblade · Sep 25, 2012 at 07:47 AM 0
Share

im sort of new to coding in unity so im not sure how to put that into my scripts that I have, here is my run/crouch script:

var walkSpeed: float = 3; // regular speed

var crchSpeed: float = 1.5; // crouching speed

var runSpeed: float = 5; // run speed

private var ch$$anonymous$$otor: Character$$anonymous$$otor;

private var tr: Transform;

private var dist: float; // distance to ground

function Start(){

 ch$$anonymous$$otor = GetComponent(Character$$anonymous$$otor);

 tr = transform;

 var ch:CharacterController = GetComponent

(CharacterController);

 dist = ch.height/2; // calculate distance to ground

}

function Update(){

 var vScale = 1.0;

 var speed = walkSpeed;
 
 if (ch$$anonymous$$otor.isGrounded && Input.Get$$anonymous$$ey("right shift") || 

Input.Get$$anonymous$$ey("left shift")){

     speed = runSpeed;

 }

 if (Input.Get$$anonymous$$ey("v")){ // press V to crouch

     vScale = 0.5;

     speed = crchSpeed; // slow down when crouching

 }
 ch$$anonymous$$otor.movement.maxForwardSpeed = speed; // set max speed

 var ultScale = tr.localScale.y; // crouch/stand up smoothly 

 tr.localScale.y = $$anonymous$$athf.Lerp(tr.localScale.y, vScale,

5*Time.deltaTime);

 tr.position.y += dist * (tr.localScale.y-ultScale); // fix

vertical position

}

avatar image soulblade · Sep 27, 2012 at 04:51 AM 0
Share

the script didnt really work so if anyone else has any anwsers please submit.

avatar image Fattie · Sep 27, 2012 at 07:06 AM 0
Share

You use Invoke(), InvokeRepeating() and InvokeCancel() for very easy timers in Unity3D. You can find 1000s of examples on this site.

 Invoke( "changeToCrouchSpeed", 3.5 );

etc.

0 Replies

· Add your reply
  • Sort: 

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

Deactivating a power up script after a certain amount of time 1 Answer

Removing the tenths of seconds on a timer 3 Answers

Stealth AI Script. If less than or equal to not working correctly. Any fixes ? 1 Answer

Problems with scripts 0 Answers

Whats a good sprinting script? 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