- Home /
Terrain texture specific step sounds?
Hello all, I'm working on a survival game and I would like to know how to make footstep sounds that are based off of the terrain texture. For instance grass having grass noise and sand having sand noise. You get what I'm saying I presume. But how do I do this? I've searched everywhere and do not want to pay. (Javascript preffered)
Answer by siaran · May 09, 2015 at 11:15 AM
Well, here is an answer on how to get the terrain texture at a point on the terrain: http://answers.unity3d.com/questions/456973/getting-the-texture-of-a-certain-point-on-terrain.html
Once you have that, I guess you could do something like
public var grassSound : AudioClip;
public var sandSound : AudioClip;
public var audioPlayer : AudioSource;
var previousTextureType;
var currentTextureType;
function SetSound(){
if(currentTextureType != previousTextureType){
if(currentTextureType == "Grass") audioPlayer.clip = grassSound;
else if(currentTextureType == "Sand") audioPlayer.clip = sandSound;
previousTextureType = currentTextureType;
}
}
function GetCurrentTexture(){
//here do something to get current texture type. see link above.
}
function Update(){
GetCurrentTexture();
SetSound();
}
my SetSound function here just changes the audio clip of the audiosource when the texturetype changes. which I have sort of assumed is a string here, but see the link above for how to get it. I haven't put in any code to start/stop playing as that's a separate issue.
Also I'm more of a c# person so maybe there are javascript errors.
Your answer
Follow this Question
Related Questions
Play and stop sound 1 Answer
Play sound when out of ammo 0 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
I have problems with coding 0 Answers