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 Carvuh · Mar 30, 2013 at 07:26 PM · audiofootstepsaudio.clip

audio.clip Messing with Other Audio Clips?

Hey guys, new to Unity, and I was wondering what the heck is wrong with my code? I have a GameObject with a Capsule Collider set up on it and have "isTrigger" checked.

Here the code that is messing up:

 var sound : AudioClip;
 var volume = 0.5;
 var triggered = false;
 
 function OnTriggerEnter(otherObj: Collider){
     
     audio.clip = sound;
     audio.volume = volume;
 
     if (otherObj.tag == "Player"){
        if (Input.GetKeyDown(KeyCode.E)) {
            triggered = true;
        }
     }
     if (triggered) {
         sound.Play();
     } 
 }

I also have my character that everytime he walks, a footstep sound plays, Now, I know this is not the most effiecent way to do this with the footsteps but I was in a rush to leave for work. Here is the code for that: var AudioFile : AudioClip; var Volume: float; //Code wont function properly. If two buttons are pressed at once, it starts the sound clip over again and wont play correctly.

 var AudioFile : AudioClip;
 var Volume: float;
 //Code wont function properly. If two buttons are pressed at once, it starts the sound clip over again and wont play correctly.
 
 function Update() {
 
 audio.volume = Volume;
 audio.loop = true;
 
 if (Input.GetKeyDown (KeyCode.W))
 {
     audio.clip = AudioFile;
     audio.Play();
  
     }
     if (Input.GetKeyUp(KeyCode.W))
     {
     audio.Pause();
  
     }
 else if (Input.GetKeyDown (KeyCode.A))
 {
     audio.Play();
  
     }
     else if (Input.GetKeyUp(KeyCode.A))
     {
     audio.Pause();
  
     }
 else if (Input.GetKeyDown (KeyCode.S))
 {
     audio.Play();
  
     }
     else if (Input.GetKeyUp(KeyCode.S))
     {
     audio.Pause();
  
     }
 else if (Input.GetKeyDown (KeyCode.D))
 {
     audio.Play();
  
     }
     else if (Input.GetKeyUp(KeyCode.D))
     {
     audio.Pause();
  

Now, I think the audio.clips are messing with each other, but I dont know how to fix it? I walk up into the trigger, and when I hold down "E", the sound will ONLY play cut up when I walk backwords out of the trigger?

Can anyone help?

P.S. If you guys could help with the correct efficient way to code the footsteps, that would be awesome. The code only plays when 1 key is held down, not two, or three. When two or more are held down, the footstep sound stops completely.

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

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

Multi-Surface footsteps with FPSController 0 Answers

Footstep audio for FPS 1 Answer

How to add footsteps to Lerpz? 1 Answer

Random Footsteps within CollisionSoundEffects Script 1 Answer

Footsteps with iTween MoveTo 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