Footsteps on different terrain idea

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 :slight_smile: 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;
 

function Start() 

{

    audio.clip = footsteps;

    audio.loop = true;

}

// function start_2 ()

{

    audio.clip = mud;

    audio.loop = true;

}


 

function Update()

{

    if (Input.GetKeyDown (KeyCode.W))

    audio.Play();

    else if(Input.GetKeyUp (KeyCode.W))

    audio.Stop();

}

I already see errors but what you guys think :slight_smile: ill work on some pseudocode tonight

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
	
	void Update()
	{
		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 :frowning: