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 Vacciones_Mad · Jan 03, 2014 at 05:07 PM · bugsoundfootstepsogg vorbis

My Running sound doesn't play or sound as it should, Help

Hello, I've been reading how to add footsteps sound and sounds in general to the game and think I've got about the right idea but there are certain sound that don't play as they should, This is the script for a 2d like Castlevania or Dust Elysian Tale.

 if (Input.GetKey(KeyCode.RightArrow) && !Playing_Left && Milu_Grounded && !Ground_First_Press && Skip_Next_Movement && !Milu_Airborne && !Facing_Left){
             Vector3 right = transform.TransformDirection(Vector3.right);
             if (rigidbody.velocity.x < (Movement_Speed_Walk/3.7f) && !Milu.IsPlaying("Crouch")){
             rigidbody.AddForce(right * (Movement_Speed_Walk/3.7f) , ForceMode.Impulse);
             }
             if (!Milu.IsPlaying("Walk")) {
                 Milu.Play("Walk");
                 Walking_Milu = true;
                 Idle_Milu = false;
                 Playing_Right = true;
                 Facing_Left = false;
                 Crouching_Milu = false;
                 Milu_Landing = false;
                 Space_Bar_Hold = false;
                 Running_Milu = false;
                 Skip_Next_Movement = true;
                 Time_Lapse_Walk = Time.time; // Esta linea crea un margen de tiempo entre el tiempo real y el "Time_Lapse_Walk"
                                              // para revisar si se esta dentro de este margen de tiempo y se detecte el double-tap
                 if(Walking_Milu && Milu_Grounded){
                 audio.volume = 0.4f;
                 audio.clip = Walking_HardFloor_Sound;
                 audio.Play();
                 audio.loop = true;
                 }
             }
         }
         
         /* Este pedazo de aqui invierte  el "!Ground_First_Press && Skip_Next_Movement" a "Ground_First_Press && !Skip_Next_Movement"
          * cuando se suelta la techa de la flecha derecha, para que cuando se vuelva a presionar la flecha se revisen y se pueda correr*/
         if (Input.GetKeyUp(KeyCode.RightArrow) && Facing_Left == false){
             Skip_Next_Movement = false;
             Ground_First_Press = true;
             Walking_Milu = false;
             Milu_Landing = false;
             //audio.Stop();
         }
         
         /* Aqui ocurre practicamente lo mismo que en Walk exceptuando que esto se ejecuta si se esta dentro del margen de tiempo
          * previamente creado y "!Ground_First_Press && Skip_Next_Movement" estas invertidas, se aplica una fuerza con otros valores
          * y se corre la animacion "Run"*/ 
         if (Input.GetKey(KeyCode.RightArrow) && ((Time.time - Time_Lapse_Walk) < Time_Lapse_Run && Ground_First_Press && !Skip_Next_Movement && !Playing_Left && !Milu_Airborne) || (Running_Milu && !Playing_Left && !Milu_Airborne)){
             Vector3 right = transform.TransformDirection(Vector3.right);
             if (rigidbody.velocity.x < (Movement_Speed_Walk*0.9f) && !Milu.IsPlaying("Crouch")){
             rigidbody.AddForce(right * (Movement_Speed_Walk*0.9f) , ForceMode.Impulse);
             }
             Milu.Play("Run");
             Walking_Milu = false;
             Idle_Milu = false;
             Facing_Left = false;
             Playing_Right = true;
             Crouching_Milu = false;
             Milu_Landing = false;
             Space_Bar_Hold = false;
             Running_Milu = true;
             Ground_First_Press = true;
             Skip_Next_Movement = false;
             Time_Lapse_Walk = Time.time;
             if(Running_Milu && Milu_Grounded){
             audio.clip = Running_HardFloor_Sound;
             audio.Play();
             audio.loop = true;
             }
         }


// Comments are in spanish, my language so I dont forget what I did there

It starts playing like it should, the walking sounds plays but when the character runs it plays some sort of static while its grounded, yet if I jump while running the sound plays correctly, I really dont understand why.

Thanks.

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
0

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

It's easy Heres the script...The only Flaw is that it plays the sound while in air...

  • Paste the script in the new script you made...

  • Add it to the cam...

  • Put your sound and Test.

Script:

 #pragma strict
  
 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();
 }
 }

Enjoy.

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:34 PM 0
Share

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

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Footsteps? 4 Answers

Simple footsteps? 1 Answer

Sprinting Audio Problem 1 Answer

Footsteps Problem 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