I would like to do this, but I havent been exposed to the elements in C# that would let me do this. Could someone help? I need a good explanation.
I would also like to know this.
The best way I currently know of is to simply have a global (level-wide) footstep sound bank corresponding to the type of terrain you're most likely to walk on (for example grass), and then manually add trigger boxes which temporarily override the sound over other surfaces (like gravel path or rocks) over the areas that need changing.
But that results in clear cut to another sound type and sometimes you don't want that, and also it's a pain in the butt to set up if you have curvy roads or a lot of different surfaces of the terrain.
Either raycast downwards and check for some value, for example the material that is used for the object that was hit, or (for tile-based meshes) do it by continuously checking the player's x,y position against the tile array and finding out the texture/terrain type/whatever that way. Then you need to play the right sound depending on the texture/terrain type, for example by keeping a dictionary where string is the material name.
And what about non-tiled, single terrain?
As I have written, you can get the material of the object that was hit by the raycast by accessing it's MeshRenderer component. If the objects has multiple materials, you might have to use GetTriangleIndex or similar to get the right one.
@Eudaimonium How can I do that for terrain?
this explains how to determine the different materials on a terrain, I'm not exactly sure how its done but it seems you can check the weight of the splatmap.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
36 People are following this question.
Raycasthit explanation wanted.
Explain location of Database Files with SQLite
Shader metallic effect
Picture frame around minimap