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 inglipX · Mar 27, 2013 at 05:11 PM · javascriptaudiofootsteps

My Footstep isn't working

I wrote up this javascript and have no compiler errors, but when i walk i don't hear any footstep sounds. What's wrong? I tagged the objects correctly too.

 var AudioTimer : float = 0;
 
 var ConcreteSound: AudioClip;
 var MetalSound: AudioClip;
 
 
 function Update () {
 
     if(AudioTimer > 0){
     
     AudioTimer -= Time.deltaTime;
     
     }
 
 
     if(AudioTimer < 0){
     
     AudioTimer = 0;
     
     }
     
 
 
 }
 
 
 
 function OnControllerColliderHitt (col: ControllerColliderHit){
 
     if(col.gameObject.CompareTag("concrete") && Input.GetAxis("Vertical") && AudioTimer == 0 ||
     Input.GetAxis("Horizontal") && AudioTimer == 0 ){
     
     audio.clip = ConcreteSound;
     audio.PlayOneShot(ConcreteSound);
     AudioTimer = 0.5;
     
     }
     
     if(col.gameObject.CompareTag("metal") && Input.GetAxis("Vertical") && AudioTimer == 0 ||
     Input.GetAxis("Horizontal") && AudioTimer == 0 ){
     
     audio.clip = MetalSound;
     audio.PlayOneShot(MetalSound);
     AudioTimer = 0.5;
     
     }
 
 }
 
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 sparkzbarca · Mar 27, 2013 at 05:51 PM

OnControllerColliderHitt 2 t's?

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 inglipX · Mar 27, 2013 at 06:09 PM 0
Share

This is what i have, stll doesnt work

 var AudioTimer : float = 0;
 
 var ConcreteSound: AudioClip;
 var $$anonymous$$etalSound: AudioClip;
 var isWalking: boolean = false;
 var controller : CharacterController = GetComponent(CharacterController);
 
 
 function Update () {
 
     if(AudioTimer > 0){
     
     AudioTimer -= Time.deltaTime;
     
     }
 
 
     if(AudioTimer < 0){
     
     AudioTimer = 0;
     
     }
     
 
 
 }
 
 
 
 function OnControllerColliderHit (hit: ControllerColliderHit){
 
     if(hit.gameObject.tag == ("concrete") && Input.GetAxis("Vertical") && AudioTimer == 0 && controller.isGrounded ||
     Input.GetAxis("Horizontal") && AudioTimer == 0 && controller.isGrounded ){
     
     Debug.Log ("isWalking");
     isWalking = true;
     audio.clip = ConcreteSound;
     audio.PlayOneShot(ConcreteSound);
     AudioTimer = 0.5;
     
     }
     else
     {
     isWalking = false;
     audio.Stop();
     }
     
     if(hit.gameObject.tag == ("metal") && Input.GetAxis("Vertical") && AudioTimer == 0 ||
     Input.GetAxis("Horizontal") && AudioTimer == 0 ){
     
     Debug.Log ("isWalking");
     isWalking = true;
     audio.clip = $$anonymous$$etalSound;
     audio.PlayOneShot($$anonymous$$etalSound);
     AudioTimer = 0.5;
     
     }
     else
     {
     isWalking = false;
     audio.Stop();
     }
 
 }
     
 
avatar image
0

Answer by fafase · Mar 27, 2013 at 05:57 PM

This is not going to work anyway, the character controller is a capsule over the whole character so it won't do what you expect. It does not collide the feet. You may want to use isGrounded instead to check if you are ...grounded.

All you need is to play a looping footstep sound while walking:

 if(Input.GetAxis("Vertical")&& controller.isGrounded){
    //Movement
    audio.Play
 }else 
    audio.Stop();

This is simplified version. Make sure your audio is looping. That could do it. controller stands for the reference to your character controller.

Comment
Add comment · Show 2 · 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 inglipX · Mar 27, 2013 at 06:00 PM 0
Share

i deleted the capsule graphics from it

avatar image fafase · Mar 27, 2013 at 06:46 PM 0
Share

No capsule no character controller. $$anonymous$$eep the capsule but do not use it for the purpose of footstep sound. I can help you more than that...you are heading the wrong way trying to do your sound system into the collision function.

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

12 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

Related Questions

Footstep Audio Check Collider Hitting Floor 1 Answer

Footsteps script not working 2 Answers

Random Audioclip. No Repeat ?? 1 Answer

Playing audio when a button is clicked? 1 Answer

Audio loop after time 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