# the script does not work!

**URL:** https://discussions.unity.com/t/the-script-does-not-work/497956
**Category:** Scripting
**Tags:** Scripting
**Created:** [February 19, 2013, 8:04pm UTC](https://discussions.unity.com/t/the-script-does-not-work/497956 "2013-02-19T20:04:47Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Gtripoli](https://avatars.discourse-cdn.com/v4/letter/g/43a26b/32.png) [@Gtripoli](https://discussions.unity.com/u/Gtripoli)
#### Post date: [February 19, 2013, 8:04pm UTC](https://discussions.unity.com/t/the-script-does-not-work/497956/1 "2013-02-19T20:04:47Z")

</div>

Good evening to all, because the script for FPS, which simulates the sound of footsteps on different surfaces, does not work!

```php
public var footAudioSource : AudioSource;
public var woodSteps : AudioClip[ ];
public var metalSteps : AudioClip[ ];
public var concreteSteps : AudioClip[ ];
public var sandSteps : AudioClip[ ];
public var waterSteps : AudioClip[ ];
public var grassSteps : AudioClip[ ];
private var cc : CharacterController;
private var t : Transform;
public var hitLayer : LayerMask;
private var cTag : String;
	
function Start()
{
cc = GetComponent(CharacterController);
t = transform;
}
function OnFootStrike () 
{
if(Time.time < 0.5) return;
if(cc != null)
{
volume = Mathf.Clamp01(0.1 + cc.velocity.magnitude * 0.3);
}
else
{
volume = 1;
}
footAudioSource.PlayOneShot(GetAudio(), volume);
}
function GetAudio() : AudioClip
{
var hit : RaycastHit;
if(Physics.Raycast(t.position + new Vector3(0, 0.5, 0), -Vector3.up, hit, Mathf.Infinity, hitLayer))
{
cTag = hit.collider.tag.ToLower();
}
if(cTag == "Wood")
{
return woodSteps[Random.Range(0, woodSteps.length)];
}
else if(cTag == "Metal")
{
return metalSteps[Random.Range(0, metalSteps.length)];
}
else if(cTag == "Floor")
{
volume = 0.8;
return concreteSteps[Random.Range(0, concreteSteps.length)];
}
else if(cTag == "Sand")
{
volume = 1.0;
return sandSteps[Random.Range(0, sandSteps.length)];
}
else if(cTag == "Water")
{
volume = 1.0;
return waterSteps[Random.Range(0, waterSteps.length)];
}
else if(cTag == "Grass")
{
volume = 1.0;
return grassSteps[Random.Range(0, grassSteps.length)];
}
}

```

Thanks in advance.

---

<div class="post-metadata">

### Author: ![MikeBastien](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/mikebastien/32/441649_2.png) [@MikeBastien](https://discussions.unity.com/u/MikeBastien)
#### Post date: [February 19, 2013, 8:24pm UTC](https://discussions.unity.com/t/the-script-does-not-work/497956/2 "2013-02-19T20:24:46Z")

</div>

Did you assign the appropriate materials to the surfaces in your scene?

> **[What's the easiest way of changing footsteps sound depending on floor material?](https://discussions.unity.com/questions/15928/whats-the-easiest-way-of-changing-footsteps-sound.html)**
>
> Hi I know basically nothing about coding and have so far just been taking scripts from various places in order to get my game to work. At the moment I have a script which plays random footstep sounds when I walk, which is fine, but I want to change...

---

<div class="post-metadata">

### Author: ![Gtripoli](https://avatars.discourse-cdn.com/v4/letter/g/43a26b/32.png) [@Gtripoli](https://discussions.unity.com/u/Gtripoli)
#### Post date: [February 19, 2013, 8:30pm UTC](https://discussions.unity.com/t/the-script-does-not-work/497956/3 "2013-02-19T20:30:44Z")

</div>

Yes, of course I tagged all surfaces.  
But maybe I missed something.

---

<div class="post-metadata">

### Author: ![mgear](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/mgear/32/886412_2.png) [@mgear](https://discussions.unity.com/u/mgear)
#### Post date: [February 19, 2013, 8:33pm UTC](https://discussions.unity.com/t/the-script-does-not-work/497956/4 "2013-02-19T20:33:36Z")

</div>

Try with print(), to see what tags it returns (if any),

```auto
cTag = hit.collider.tag.ToLower(); 
print ("we hit:"+cTag);

```

---

<div class="post-metadata">

### Author: ![Gtripoli](https://avatars.discourse-cdn.com/v4/letter/g/43a26b/32.png) [@Gtripoli](https://discussions.unity.com/u/Gtripoli)
#### Post date: [February 19, 2013, 8:37pm UTC](https://discussions.unity.com/t/the-script-does-not-work/497956/5 "2013-02-19T20:37:32Z")

</div>

Assets/Scripts/AudioManager.js(31,10): BCW0023: WARNING: This method could return default value implicitly.

---

<div class="post-metadata">

### Author: ![KelsoMRK](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kelsomrk/32/205687_2.png) [@KelsoMRK](https://discussions.unity.com/u/KelsoMRK)
#### Post date: [February 19, 2013, 9:06pm UTC](https://discussions.unity.com/t/the-script-does-not-work/497956/6 "2013-02-19T21:06:07Z")

</div>

ToLower() makes every character lowercase so it will never equal a string that starts with an uppercase letter. 🙂 Curious why you’re even bothering making it lowercase in the first place?
