Forum rules - please read before posting.

Speech with 1 sound per dialogue line?

Hi, I'm wondering if it's possible to make it so that a speech sound effect plays once per dialogue? 

I have speechsfx1.mp3 attached to my NPC Text Scroll Override (each character has a different sound), and at the moment while watching the text scroll, the sound plays about every second, when I want it to only play once. I can't find any options to change this and there's only an option for a sound every syllable which is the complete opposite of what I want haha
Basically so that the sound plays only once in a dialogue.

Thank you!

Comments

  • edited June 2017
    Welcome to the community, @admiralamott.

    Audio sounds normally come in two flavours - actual speech of the line in question (played once) or scrolling audio (played continually).

    To play a scrolling sound just once, you could try extending the length of the scound with some silence, as AC won't play another instance of the sound until the previous one has finished (unless Play audio on every letter? is checked in the Speech Manager).

    Alternatively, if you're comfortable with some very simple coding, you could write a hook for the OnStartSpeech event that plays the audio clip through script.  The OnStartSpeech event is demonstrated in the custom events tutorial.  To play an audio clip without an audio source, you can just use:

    AudioSource.PlayClipAtPoint (myAudioClip, AC.KickStarter.mainCamera.transform.position);

    Which will play the audio clip variable "myAudioClip" at the same position as AC's MainCamera.
  • Hi Chris,
    What do I have to do to 'create' the myAudioClip variable? Or what do I replace it with? 
    Because when I use it in game or replace myAudioClip with something else it just does this

    error CS0103: The name `myAudioClip' does not exist in the current context
    error CS1502: The best overloaded method match for `UnityEngine.AudioSource.PlayClipAtPoint(UnityEngine.AudioClip, UnityEngine.Vector3)' has some invalid arguments
    error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEngine.AudioClip'

    (I've never coded before lol)
  • The issue is that the AudioClip variable simply needs to be defined outside of the function, so that you can assign it in the Inspector:

    public AudioClip myAudioClip;

    Place the above outside of the function (but inside the class) and you should find it as a field in the component's Inspector.  You can then place the script on a GameObject in your scene, assign the audio clip in its Inspector and it should all work.
  • edited June 2017
    Editing yet again, I figured that out haha
    Thanks Chris!
  • Ok one more question and I'll go away
    When I try to compare if speakingCharacter is equal to test, it says 
    Operator `==' cannot be applied to operands of type `AC.Char' and `string'


    My code:
    using UnityEngine;
    using System.Collections;
    using AC;

    public class VoiceSound2 : MonoBehaviour {
    public AudioClip myAudioClip;
    public AudioClip myAudioClip2;

    // Use this for initialization
    void GetSpeech (AC.Char speakingCharacter, string speechText, int lineID) 
    {
    if (speakingCharacter=="Test")
    {
    float randValue = Random.value;
    if (randValue < .50f) 
    {
    AudioSource.PlayClipAtPoint (myAudioClip, AC.KickStarter.mainCamera.transform.position);
    }
    else if (randValue < .50f) 
    {
        AudioSource.PlayClipAtPoint (myAudioClip2, AC.KickStarter.mainCamera.transform.position);
    }
    }

    }
    private void OnEnable()
    {
    EventManager.OnStartSpeech +=GetSpeech;
    }
    private void OnDisable()
    {
    EventManager.OnStartSpeech -=GetSpeech;
    }
    }

  • As the warning suggests, you're comparing the character's name with the character itself.  If the name "Test" is the name of the character's GameObject, just use:

    if (speakingCharacter != null && speakingCharacter.gameObject.name == "Test")

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.