Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Oct 18, 2016 at 10:44 PM by Zitoox for the following reason:

Fixed it by myself.

avatar image
0
Question by Zitoox · Oct 16, 2016 at 02:13 AM · javascriptsoundplayfootstepseach

Make footstep script

Hi! There is a scene in my game that have water., and i wanted to make a script that add (or play) footstep sounds when my character walks in the water. Can someone help me? I have been trying to do this about a week for now and i didn't get any result.

I wanted to make something like this:

The player is walking normaly in the map, making it's default footstep sounds (it is a First Person Character). Then he enters in the water. EVERY TIME he walk, a sound is played. There are two different sounds, one for each foot.

The problem is that i don't know how to make the sound repeat or something, and i don't know how to get two sounds to play at the same time =\ I am using JavaScript, but i would accept C# too.

Here's my script:

 #pragma strict
 
 
 function OnTriggerEnter (o:Collider) {
 
     //Below is the code to play the Audio Source attached to the Game Object (the water)
     
         GetComponent.<AudioSource>().Play();
     }
 
     // The OnTriggerExit function is kinda disabled because i don't need to add anything on it.
 
     function OnTriggerExit (o:Collider) {
         
     }

This is a very simple Java-Script that play a sound attached to an audio source when the player hit the object's collider. In my case, the object with this script will be the water. Can someone help me? I don't have any idea to how to make this...

Comment
Add comment · Show 2
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 Cherno · Oct 17, 2016 at 09:11 AM 0
Share

First, you have to check if the player is in the water. You can do this via Raycasting, or the OnTrigger function. Your choice. To play two audioclips simultaneously, you need two AudioSource components.

avatar image Zitoox Cherno · Oct 17, 2016 at 10:37 PM 0
Share

Yeah, but how do i reference the two? Do i just type for example:

 GetComponent.<AudioSource1>().Play();
 GetComponent.<AudioSource2>().Play();

Is that correct? And what about the detection? The OnTriggerFunction detects only when the player touch the trigger for the first time, and it doesn't register if the player have touched it again until it isn't there.

2 Replies

  • Sort: 
avatar image
0

Answer by ZBlaxland · Oct 17, 2016 at 05:00 AM

Hopefully this helps :D

https://www.youtube.com/watch?v=-JFW1cbuJww

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 Zitoox · Oct 17, 2016 at 10:39 PM 0
Share

Unfortunately, SpeedTutors' videos doesn't work in Unity 5, almost every script that he made are uncompatible.

avatar image
0

Answer by Naphier · Oct 18, 2016 at 07:04 AM

First, your game object can have multiple audio sources, your script should have a public AudioSource variable naming each sound (waterWalk, groundWalk, jumpLanding, etc). Second, you should do this with animation clip events. You can set up a trigger on them to run a method at specific points in the animation clip (let's call this method OnStep()). That script must be on the same game object as the animator controller. This script will need to know what type of terrain the player is on, this would likely be done through OnCollisionEnter then check the tag of the other collision (ground, water, etc). Then depending on that the just call waterWalk.Play() in the OnStep method.

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

Follow this Question

Answers Answers and Comments

89 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 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 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 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 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

'Play' is not a member of 'Object' 1 Answer

Get key down looped sound? 0 Answers

Play a sound when flicker? 1 Answer

Sound Effect won't play! 1 Answer

How to play two sounds at once on same object 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