Forum rules - please read before posting.

A couple of issues

The first one is not much of an issue for me because I currently don't need to animate my main cursor, but changing its texture with AC.KickStarter.cursorManager.pointerIcon.texture = mainCursor; only works with non-animated cursors. If the cursor is animated, I will see the texture change in the manager, but not in the actual game.

The second issue is that I have a marker prefab with an audio source child with a Sound component, an animation controller (with an 'intro' animation that transitions into an 'idle' one, and an 'exit' animation that plays when a 'pathfinding' bool parameter is false). I also have two custom scripts attached here: (1) allows me to play a sound through a specified audio source as an animation event, and (2) checks if the player is pathfinding and sets the animator parameter accordingly.

The intended result is that clicking on the screen will place a marker where the player is pathfinding to, and when the marker is placed, it will do so with a little intro animation and a sound effect. The marker will only disappear when the player has finished pathfinding, at which point it will play an exit animation.

I've got this working correctly, mostly. The only issue I'm having is that despite the fact that the sound IS playing through the child source (I've checked), the Sound component doesn't seem to route it through AC's SFX volume. Even if my SFX volume is set to 0, you'll still be able to hear it (and this is the only sound effect this happens to). The Sound component is working to some capacity because the audio source's volume is changing to 1 and can't be adjusted through the inspector at runtime, which doesn't happen when I disable the Sound component.

Any idea why this is happening?

Comments

  • but changing its texture with AC.KickStarter.cursorManager.pointerIcon.texture = mainCursor; only works with non-animated cursors.

    Using the ReplaceTexture function will correctly update a cursor texture - including animated - at runtime.

    despite the fact that the sound IS playing through the child source (I've checked), the Sound component doesn't seem to route it through AC's SFX volume.

    Are you using the Sound component to play the audio? i.e.:

    GetComponent<Sound> ().Play ();
    
  • edited April 2023

    Ahh, right, I wasn't! And I'm sure I'm doing something stupid, but is this not supposed to work? I've commented out the original lines and replaced them with the sound component lines. Now the clips are not being played at all. Am I supposed to use a slightly different syntax?

        using System.Collections;
        using System.Collections.Generic;
        using UnityEngine;
        using AC;
    
        public class PlaySoundFromList : MonoBehaviour
        {
    
            public AudioSource audioS;
            public List<AudioClip> soundClips = new List<AudioClip>();
    
            //Store a private counter variable to keep track in case clips go in order
            private int _clipCounter = 0;
    
            private void Start()
            {
                if (audioS == null)
                    Debug.LogError("The AudioSource is NULL on " + gameObject.name);
            }
    
            public void PlayRandomClip()
            {
                //Make sure a sound clip exists in the list
                if (soundClips.Count == 0)
                    Debug.LogError("No Audio Clip exists for item " + gameObject.name);
                else
                {
                    //Pick a random sound from the list
                    int randomSelected = Random.Range(0, soundClips.Count);
                    // audioS.PlayOneShot(soundClips[randomSelected]);
                    audioS.gameObject.GetComponent<Sound>().Play(soundClips[randomSelected]);            
                }
    
            }
    
            public void PlayNextClip()
            {
                // audioS.PlayOneShot(soundClips[_clipCounter]);
                audioS.gameObject.GetComponent<Sound>().Play(soundClips[_clipCounter]);
    
                //increment the clip counter, returning to 0 if needed
                _clipCounter++;
                if (_clipCounter >= soundClips.Count)
                    _clipCounter = 0;
            }
    
            public void PlayClipAt(int selected)
            {
                if (soundClips.Count > selected)
                {
                    // audioS.PlayOneShot(soundClips[selected]);
                    audioS.gameObject.GetComponent<Sound>().Play(soundClips[selected]);
                }
                else
                {
                    Debug.LogError("A clip has been specified for " + gameObject.name + " but the list does not contain that many clips");
                }
            }
    
        }
    

    I also tried simplifying this by changing audioS to be a public Sound component rather than an AudioSource, and then using something like audioS.Play(soundClips[randomSelected]);, but it didn't work either.

  • That ought to work. What's the Sound Inspector's Sound type set to, and what is the current volume for that type?

  • It was a super simple solution. audioS.Play(soundClips[randomSelected]); doesn't work, but audioS.Play(soundClips[randomSelected], false); does.

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.