I have a idea, im at college right now so cant get access to unity. Been on a roll with programming recently. If i make a extra variable in this code then a if statement that basically if a gameobject is hit then it changes the sound to the new variable? I will try it out later :) then i can add a new variable for all teh curface types and just add a plane onto the surface with mesh render off.. hmmm
var footsteps : AudioClip;
//INSERT NEW VARIABLE VAR MUD :Audioclip;
audio.clip = footsteps;
audio.loop = true;
// function start_2 ()
audio.clip = mud;
audio.loop = true;
if (Input.GetKeyDown (KeyCode.W))
else if(Input.GetKeyUp (KeyCode.W))
I already see errors but what you guys think :) ill work on some pseudocode tonight
Answer by XxRoflPwnxX
Apr 25, 2013 at 01:43 AM
If you want to be able to detect what you are walking on you would definitely need a raycasthit and tags on your gameObjects to trigger the right audio
private RaycastHit hit; // What terrain we hit
public Transform Character_T; // The transform (Position) of our character
private float Speed = 1.0f; // How fast the character moves
transform.Translate (0,0,Speed * Time.deltaTime);
if(Physics.Raycast(Character_T.position,-Vector3.up,out hit,100.0f)) // Send out a ray from character position down at 100.0f, if java, forget the out modifier
print ("I be firing my ray");
if(hit.collider.tag == "Mud_Terrain" && Speed >= .1f) // If we are walking on mud terrain
audio.Play(); // Play the mud terrain audio
I didn't define a mud audio in the script though :(
nice idea, obviously you would need to incorporate the if w is pressed part in there. I have actually got it working by a variety of different ways. just wanted to know if anyone else did what i said
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
12 People are following this question.
FPS footsteps only work when jumping/hitting edges of a mesh
Footstep sounds when walking
Just footsteps, that's all I ask...
How can I add sound to walk animation please?
PlayOneShot on footstep script either plays very delayed or not at all.