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 ZdzichuRonczka · Aug 24, 2014 at 02:42 PM · animationaudiosounds

[JS]Sounds with animation issue

Hey, i'm new in unity and i got a few problems. I want to change the walk sound activated from key to animation (parent sound to animation once). This is my source code:

 #pragma strict
 var fwalk : AudioClip;
 
 function Update () {
 
         if (animation["fwalk"].enabled == true){
     print("fwalk");
     audio.clip = fwalk;
     audio.Play();
 }
 
         else if (animation["run"].enabled == true){
     print("run");
     audio.clip = fwalk;
     audio.pitch = 2.2;
     audio.Play();
 }
 }

And now the problem. whenever i press the move key on keyboard, there is just no sounds. but after running/walking when i unpress the move key, the walking/running sound playing. Someone know what happend and how to fix this ?

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 Nerevar · Aug 24, 2014 at 10:31 PM 0
Share

hello,

it depends what is in your audio clip but if the sound is too long, you restart playing it everyframe... try to add the condition: if(!audio.isPlaying) before playing any sound.

$$anonymous$$aybe check this example, it seems safer to have the states of your player (running/walking), it might be useful if you go further in its programmation.

avatar image ZdzichuRonczka · Aug 25, 2014 at 03:30 PM 0
Share

Now the walk sound is just not playing all the time. weird :< .

avatar image ZdzichuRonczka · Aug 26, 2014 at 08:50 AM 0
Share

But if i just parent to colliders itself, than sound will play always, and not just while i moving the character :) .

avatar image ZdzichuRonczka · Aug 27, 2014 at 08:19 PM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class sound2animation : $$anonymous$$onoBehaviour {
     
     AudioClip fwalk;
     
     void  OnCollisionStay(Collision mapa){
         
         if (animation.IsPlaying("fwalk")){
             print("fwalk");
             audio.clip = fwalk;
             audio.Play();
         }
         
         else if (animation.IsPlaying("run")){
             print("run");
             audio.clip = fwalk;
             audio.pitch = 2.2f;
             audio.Play();
         }
     }
 }

This is the c# code, and the problems is now, the walk sound actually play all over without stopping, and already pitch to 2.2f as the last part of the code. Someone can help me fix this ?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by meat5000 · Aug 25, 2014 at 03:33 PM

Stick colliders on the feet and play the sound on detection of the floor, in OnCollision :)

Hacktastic.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Synchronize Audio and Animation 0 Answers

Play from a variety of sounds? 1 Answer

Toggling BGM and SFX 0 Answers

Can I make animations snap to a frame? 1 Answer

stop triggers from retriggering animation 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