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 xealclianad · Apr 16, 2013 at 10:28 AM · audiofootsteps

Walking sound effect on grass

This is very simple, I just need the game to play a sound file when the character is moving then the audio will stop when the player stops. I have this script but the result is not what I expected. It keeps on looping until I release the W key on the first time then it won't play anymore on the second time.

 var AudioFile : AudioClip;
 
 function Update() 
 
 {
     if (Input.GetKeyDown (KeyCode.W))
     {
         audio.clip = AudioFile;
         audio.Playloop();
     }
     else if (Input.GetKeyUp (KeyCode.W))
     {
         audio.Stop;
     }
 }

Any idea what's wrong and what I should do? The code is in JavaScript.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ganesh.pingale · Apr 16, 2013 at 02:47 PM

     var AudioFile : AudioClip;
      
     function Update()
      
     {
     if (Input.GetKey (KeyCode.W))
     {
     audio.clip = AudioFile;
     audio.Playloop();
     }
     else
     {
     audio.Stop;
     }
     }
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
avatar image
0

Answer by Iceblitzyt · Apr 16, 2013 at 10:45 AM

I think (Sorry just restarted coding after along while) you need to make:

   else if (Input.GetKeyUp (KeyCode.W))  
     {
     audio.clip = AudioFile;
     audio.Stop();
     }
 
Comment
Add comment · Show 4 · 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 xealclianad · Apr 17, 2013 at 02:39 AM 0
Share

Sorry for such a late reply. I'm trying it now, and I will reply the results soon enough. Thanks in advance

avatar image xealclianad · Apr 17, 2013 at 02:51 AM 0
Share

Okay, here's what happened:

It starts to play at first then it wont play the second time I press W.

avatar image xealclianad · Apr 17, 2013 at 03:06 AM 0
Share

Update: Compiler Error says:

$$anonymous$$issing$$anonymous$$ethodException: UnityEngine.AudioSource.Playloop

avatar image Iceblitzyt · Apr 17, 2013 at 01:46 PM 0
Share

do

audio.Loop(); audio.Play();

avatar image
0

Answer by Griffo · Apr 16, 2013 at 10:50 AM

Try -

 #pragma strict
 
 var AudioFile : AudioClip;
  
 function Update() 
  
 {
     if (Input.GetKeyDown (KeyCode.W))
     {
        audio.clip = AudioFile;
        audio.Play();
     }
     else if (Input.GetKeyUp (KeyCode.W))
     {
        audio.Stop();
     }
 }
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 xealclianad · Apr 17, 2013 at 02:52 AM 0
Share

I tried this but it only plays once: every time I press (not hold) W. $$anonymous$$y audio file is only one footstep so as to save me some memory.

avatar image Griffo · Apr 17, 2013 at 12:21 PM 0
Share

Just add -

 audio.loop = true;

at line 11

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

14 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

Related Questions

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

AngryBots MaterialImpactManager Script and FootstepsAudio 1 Answer

Random Footsteps within CollisionSoundEffects Script 1 Answer

Help with Simple Footsteps? 2 Answers

How do I stop footstep sound from playing when I release 'w'? 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