Hi,
This code plays the sound on Unity version 5.6.7f1 but not on my PC (Windows 11/DirectX12) with Unity 2022.2.6f1. With the current version, the sound is played correctly in the preview window. After startup, the console also says AudioSource ok and Soundcheck is playing, but you can’t hear anything. AudioSource was added to the GameObject with the default settings and the AudioClip was entered in the AudioSource. Adding the audio clip in the code doesn’t work either.
Did I make a mistake?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundCheck : MonoBehaviour
{
private AudioSource audioSour;
//public AudioClip audioCli;
// Start is called before the first frame update
void Start()
{
audioSour = GetComponent<AudioSource>();
if (audioSour != null)
{
Debug.Log("SoundCheck: AudioSource ok");
//audioSour.clip = audioCli;
}
else
{
Debug.Log("SoundCheck: AudioSource error");
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.P))
{
audioSour.Play();
if (audioSour.isPlaying)
{
Debug.Log("SoundCheck is playing");
}
}
}
}
Thanks for help