Answered
0
0

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).

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(GetComponent(), accessDeniedClip)
//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(GetComponent(), doorSwishClip)
FMODUnity.RuntimeManager.PlayOneShot(“event:/Misc/Door”);
}
//}
}

  • You must to post comments
Best Answer
0
0

Have a look at http://www.fmod.org/documentation/#content/generated/engine_new_unity/script_example_basic.html

In particular FMOD.Studio.PLAYBACK_STATE and event.getPlaybackState.

  • You must to post comments
0
0

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

  • You must to post comments
0
0

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

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.