0

Script command to play sound

Pandar 2 weeks ago in Game Creator updated by ProfPivec 2 weeks ago 5

Can you tell me, please, how to play the sound through the script in the GС? Something like this:

AudioManager.Instance.PlayAudio("SpwnSound");  ??

Unity version:
Game Creator version:

if you want to use the GC Audio Manager, your script would be something like this...

AudioManager.Instance.PlaySound2D(this.audioClip, this.fadeIn, this.volume, mixer);

or for a 3D sound....

AudioManager.Instance.PlaySound3D(
this.audioClip,
this.fadeIn,
this.position.GetPosition(target),
this.spatialBlend,
this.pitch.GetValue(target),
this.volume,
mixer
);

You just need to fill in the "this." bits.

But wouldn't it be easier just to call the Action to Play Sound?

Thank you very much, but...

error CS0103: The name 'AudioManager' does not exist in the current context


You need to include using Gamecreator.core in your script.

The AudioManager is a Game Creator function, hence you must refer to that name space.

Thank you for your help, but I'm not a programmer at all. I didn't write this script and I need the sound to be played when the object is activated. Can you help me?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using GameCreator.Core;

public class SpwnFind : MonoBehaviour
{

bool ready = true;

void Start()
{
SetChildrenActiveState(false);
}

void Update()
{
if (ready && transform.position.y <= -18f)
{
StartCoroutine(DisableSpwnEff(2.0f));
}
}

IEnumerator DisableSpwnEff(float sec)
{
ready = false;
SetChildrenActiveState(true);
yield return new WaitForSeconds(sec);
ready = true;
SetChildrenActiveState(false);
}

void SetChildrenActiveState(bool active)
{
foreach (Transform child in transform)
{
child.gameObject.SetActive(active);
//AudioManager.Instance.PlaySound2D(DarknessImpаct 11.audioClip, 0.fadeIn, 1.volume, mixer);
}
}
}

If you have Game Creator (which I presume you do, or?), why do you not use the Action to Play the Sound when the Object becomes Active. There is an Action to make the Object Active, and I also think there is condition to check if it is active.

Writing or even using a script to do this defeats the purpose of having Game Creator.