# Stealth Unity Demo doubts

**URL:** <https://qa.fmod.com/t/stealth-unity-demo-doubts/12837>\
**Category:** Unity\
**Created:** [November 27, 2016, 7:12pm UTC](https://qa.fmod.com/t/stealth-unity-demo-doubts/12837 "2016-11-27T19:12:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DDAUDIOSOLUTIONS](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@DDAUDIOSOLUTIONS](https://qa.fmod.com/u/DDAUDIOSOLUTIONS)\
**Post date:** [November 27, 2016, 7:12pm UTC](https://qa.fmod.com/t/stealth-unity-demo-doubts/12837/1 "2016-11-27T19:12:01Z")

</div>

Hi, i try to remake the sound in the Steath demo of Unity, but the version of TWiiK, it’s in FPS ([http://twiik.net/projects/stealth-extended#comments](http://twiik.net/projects/stealth-extended#comments)).

I have some problems, but now my first doub is how can i transform this script, to make sound my fmod event, when the door open or close.

I think that the problem is in the void Update, but i don’t understant how i need to rewrite.

Some Help, Please??

_using UnityEngine;  
using System.Collections;  
public class DoorAnimation : MonoBehaviour {  
// Whether or not a key is required.  
public bool requireKey;  
// Clip to play when the doors open or close.  
//public AudioClip doorSwishClip;  
// Clip to play when the player doesn’t have the key for the door.  
//public AudioClip accessDeniedClip;  
// Reference to the animator component.  
Animator anim;  
// Reference to the HashIDs script.   
HashIDs hash;  
// Reference to the player GameObject.   
GameObject player;  
// Reference to the PlayerInventory script.   
PlayerInventory playerInventory;  
// The number of colliders present that should open the doors.  
int count;   
void Awake() {  
// Setting up the references.  
anim = GetComponent();  
hash = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent();  
player = GameObject.FindGameObjectWithTag(Tags.player);  
playerInventory = player.GetComponent();  
}  
void OnTriggerEnter(Collider other) {  
// If the triggering gameobject is the player…  
if (other.gameObject == player) {  
// … if this door requires a key…  
if (requireKey) {  
// … if the player has the key…  
if (playerInventory.hasKey) {  
// … increase the count of triggering objects.  
count++;  
}  
else {  
// If the player doesn’t have the key play the access denied audio clip.  
 [//AudioManager.instance.PlaySound](https://AudioManager.instance.PlaySound)(GetComponent(), accessDeniedClip)  
 [//FMODUnity.RuntimeManager.PlayOneShot](https://FMODUnity.RuntimeManager.PlayOneShot)(“event:/Misc/Acces\_Denied”);  
}  
}  
else {  
// If the door doesn’t require a key, increase the count of triggering objects.  
count++;  
}  
}  
// If the triggering gameobject is an enemy…  
else if (other.gameObject.tag == Tags.enemy) {  
// … if the triggering collider is a capsule collider…  
if (other is CapsuleCollider) {  
if (!requireKey) {  
// … increase the count of triggering objects.  
count++;  
}  
}  
}  
}  
void OnTriggerExit(Collider other) {  
// If the leaving gameobject is the player or an enemy and the collider is a capsule collider…  
if (other.gameObject == player || (other.gameObject.tag == Tags.enemy && other is CapsuleCollider)) {  
// decrease the count of triggering objects.  
count = Mathf.Max(0, count - 1);  
}  
}  
void Update() {  
// Set the open parameter.  
anim.SetBool(hash.openBool, count \> 0);  
// If the door is opening or closing…  
if (anim.IsInTransition(0) && !GetComponent().isPlaying) {  
// … play the door swish audio clip.  
 [//AudioManager.instance.PlaySound](https://AudioManager.instance.PlaySound)(GetComponent(), doorSwishClip)  
FMODUnity.RuntimeManager.PlayOneShot(“event:/Misc/Door”);  
}  
//}  
}_

---

<div class="post-metadata">

**Author:** ![DDAUDIOSOLUTIONS](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@DDAUDIOSOLUTIONS](https://qa.fmod.com/u/DDAUDIOSOLUTIONS)\
**Post date:** [November 27, 2016, 7:56pm UTC](https://qa.fmod.com/t/stealth-unity-demo-doubts/12837/2 "2016-11-27T19:56:44Z")

</div>

OK, i have good new, i have rewritten the script and now, the door sound. :)))

But, i have a problem, i don’t know how can i say to the script the condition, that if the sound is playing not replaying, because now the sound makes something like scratch,

this is the script that i have:

void Update() {  
// Set the open parameter.  
anim.SetBool(hash.openBool, count \> 0);

```
    // If the door is opening or closing...
   //if (anim.IsInTransition(0) && !GetComponent<AudioSource>().isPlaying) {
		// ... play the door swish audio clip.
		//AudioManager.instance.PlaySound(GetComponent<AudioSource>(), doorSwishClip)
	//FMODUnity.RuntimeManager.PlayOneShot("event:/Misc/Door");

	if (anim.IsInTransition(0)) //& (FMOD.Studio.PLAYBACK_STATE.PLAYING)//.isPlaying
		{
		// ... play the door swish audio clip.
		//AudioManager.instance.PlaySound(GetComponent<AudioSource>(), doorSwishClip)
		soundEvS.start();			

		           
    }
}

```

where say "…if (anim.IsInTransition(0)… I NEED SOMETHING that make reference to fmod playing the sound only if the sound is not playing.

please help.

thanks

---

<div class="post-metadata">

**Author:** ![DDAUDIOSOLUTIONS](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@DDAUDIOSOLUTIONS](https://qa.fmod.com/u/DDAUDIOSOLUTIONS)\
**Post date:** [November 29, 2016, 6:17pm UTC](https://qa.fmod.com/t/stealth-unity-demo-doubts/12837/3 "2016-11-29T18:17:11Z")

</div>

OK

Now i’m at this point

if (anim.IsInTransition(0) && sound\_Door != null)  
{

```
			//soundEvS != null;
			// ... play the door swish audio clip.
			//AudioManager.instance.PlaySound(GetComponent<AudioSource>(), doorSwishClip)
			sound_Door.start();

		}

```

BUT, i want to say sound\_Door is not playing, how can i say this, because i think that !=null i just the opposite, right?

thanks

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [December 7, 2016, 4:13am UTC](https://qa.fmod.com/t/stealth-unity-demo-doubts/12837/4 "2016-12-07T04:13:47Z")

</div>

Have a look at [http://www.fmod.org/documentation/#content/generated/engine\_new\_unity/script\_example\_basic.html](http://www.fmod.org/documentation/#content/generated/engine_new_unity/script_example_basic.html)

In particular FMOD.Studio.PLAYBACK\_STATE and event.getPlaybackState.
