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 /
This question was closed Jan 01, 2016 at 04:06 PM by SgtShadowWalker for the following reason:

Other

avatar image
0
Question by SgtShadowWalker · Jul 09, 2014 at 09:08 PM · javascriptdelaywalkingfootstepssprinting

Footsteps script

Hi,

I made a script in Javscript for random footstep sounds. But it's working half. I have a float for the delay between the sounds for the normal walk speed and idem dito for sprinting. The nextFoot float does switch from the 0.525(walkspeed) to 0.3(sprintspeed) but the delay doesn't change. If I manually change the nextFoot float in the inspector, the delay does get shorter or longer, but it doesn't work when I press Left shift.

Anyone know how I can fix this?

 private var isWalking : boolean = false;
 private var isGrounded : boolean = false;
 private var controller : CharacterController;
 
 var nextFoot : float;
 var nextFootDefault = 0.525;
 var nextFootSprint : float;
 var Steps : AudioClip[];
 
 function Awake(){
     controller = GetComponent(CharacterController);
 }
 
 
 function Update(){
     if(controller.velocity.sqrMagnitude > 0.15 ){
         isWalking = true;
     }
      else {
           isWalking = false;
      }
      
      if (Input.GetKeyDown("left shift")){
         nextFoot = nextFootSprint;
     }
     else if (Input.GetKeyUp("left shift")){
         nextFoot = nextFootDefault;
     }
 }
 
 InvokeRepeating("Walking", 0, nextFoot);
  
 function Walking(){
     if((isWalking) && (controller.isGrounded)){
         audio.PlayOneShot(Steps[Random.Range(0,Steps.length)]);
     }
 }
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

  • Sort: 
avatar image
0

Answer by RaptureFace · Jul 20, 2014 at 03:26 PM

I found a Great script but i don't know if it will please you here it is:

     var walk : AudioClip;
     var run : AudioClip;
      
     var isWalking : boolean = false;
     var isRunning : boolean = false;
      
      
     function Update()
     {
     GetState();
     PlayAudio();
     }
      
      
     function GetState()
     {
     if ( Input.GetAxis( "Horizontal" ) || Input.GetAxis( "Vertical" ) )
     {
     if ( Input.GetKey( "left shift" ) || Input.GetKey( "right shift" ) )
     {
     // Running
     isWalking = false;
     isRunning = true;
     }
     else
     {
     // Walking
     isWalking = true;
     isRunning = false;
     }
     }
     else
     {
     // Stopped
     isWalking = false;
     isRunning = false;
     }
     }
      
      
     function PlayAudio()
     {
     if ( isWalking )
     {
     if ( audio.clip != walk )
     {
     audio.Stop();
     audio.clip = walk;
     }
      
     if ( !audio.isPlaying )
     {
     audio.Play();
     }
     }
     else if ( isRunning )
     {
     if ( audio.clip != run )
     {
     audio.Stop();
     audio.clip = run;
     }
      
     if ( !audio.isPlaying )
     {
     audio.Play();
     }
     }
     else
     {
     audio.Stop();
     }
     }

(Put this in the cammera) Cheers :)

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 AlucardJay · Jul 20, 2014 at 04:18 PM 0
Share

I did a modification of my script to include a sprint timer : http://answers.unity3d.com/questions/596645/limited-sprint.html

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I get the scene to load in the background when on the loading screen? 2 Answers

Random Audioclip. No Repeat ?? 1 Answer

Issue with my Character controller script and textures? 1 Answer

More refined gunshot system 0 Answers

Instatiate inside OnTriggerEnter gives unwanted delay 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