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
1
Question by Alanj2007 · Sep 16, 2013 at 05:55 AM · audioclipfootsteps

Changing Footstep Sound When On Different Surface?

Okay. I have a script of footstep where if you walk, footstep sound will be heard. But I want to make it different when we go to different surface

I got 2 different surface in my game, cement and water. I already got footstep for cement but how to change footstep to water sound when we get in the water?

Here's the script of footstep

 var Steps : AudioClip[];
 private var isWalking : boolean = false;
 private var controller : CharacterController;
 
 function Awake()
 {
     controller = GetComponent(CharacterController);
 }
 
 function Update()
 {
     if(controller.velocity.sqrMagnitude > 0.15 )
     {
         isWalking = true;
     }
     
     else
 
     {
         isWalking = false;
     }
 }
 
 InvokeRepeating("Walking", 1.0, 0.6);
 function Walking()
 {
     if(isWalking)
     {
         AudioSource.PlayClipAtPoint(Steps[Random.Range(0,Steps.length)], gameObject.transform.position);
     }
 }
 
 

I got this script from tutorial on Youtube. I don't make this script. Do I need to change something in it? Or I need to make another script. I'm really noob at programming. I know the basics but not like this advance.

Comment
Add comment · Show 6
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 getyour411 · Sep 16, 2013 at 06:09 AM 0
Share

Yes you'll need to change some stuff. How are you going to tell if the player is walking on cement, water, ground, ice, whatever - do you already have that worked out?

avatar image Alanj2007 · Sep 16, 2013 at 06:23 AM 0
Share

This script is working for me. I don't think this script based on surfaces. This script just measure my movement and then make footstep sound be heard

avatar image getyour411 · Sep 16, 2013 at 06:30 AM 0
Share

I understand what it's doing currently, but you want it to do more such as play a different sound depending on what surface the player is walking on - - true?

avatar image Alanj2007 · Sep 16, 2013 at 06:34 AM 0
Share

true.............

avatar image getyour411 · Sep 16, 2013 at 06:36 AM 0
Share

Then I refer you back to my first comment - have you worked out how you are going to track the surface the player is walking on! Anyway, hope the vid linked by buckets gets you going.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer Wiki

Answer by Rasikh · Sep 16, 2013 at 06:50 AM

First apply a tag to surfaces. for concrete apply a tag of concrete and for water surfaces apply a tag of water.

then you can use raycast to detect on which surface you are right now. your Walking function will change as follows,

 function Walking()
 {
     if(isWalking)
     {
         var hit : RaycastHit;
        if(Physics.Raycast(transform.position, Vector3.down,hit ))
        {
               var floortag = hit.collider.gameObject.tag;
               if (floortag == "Concrete")
                 {
                     //play concrete sound code
               }
               else if (floortag == "Water")
               {
                   //play Water sound code
               }
        }
     }
 }
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 Alanj2007 · Sep 16, 2013 at 09:08 AM 0
Share

Thanks! This is working!

avatar image Kamzoki · Apr 24, 2016 at 07:15 PM 0
Share

What about if it's a terrain and it got different textures ?

avatar image
0

Answer by buckets · Sep 16, 2013 at 06:33 AM

watch this tutorial... there's a script in the description that will help you :)

http://www.youtube.com/watch?v=0nbNyJ7Vl-Y

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 Alanj2007 · Sep 16, 2013 at 09:08 AM 0
Share

Thank you! This is helpful

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

19 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

Related Questions

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

Footstep Script Not Working 2 Answers

How do I determine which frame an animation is currently playing? 1 Answer

Footstep Scipt, (What is wrong?) 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