I currently have two scripts configured in Unity to handle some UI Audio. One of them is a manager, and the other is to play a specific user interface element. A simplified version of what I have is:
public class AudioUIManager : MonoBehaviour
{
public AudioClip genericUISound;
}
public class AudioUITextAnimation : MonoBehaviour
{
[SerializeField]
private AudioClip specifiedUISound;
[SerializeField]
private AudioUIManager audioUIManager;
void Start()
{
specifiedUISound = specifiedUISound ?? audioUIManager.genericUISound;
print(specifiedUISound);
}
}
What I'm trying to achieve here is for the field to specifiedUISounduse the sound assigned to it by the inspector. If no sound is assigned, use general sound from the user interface manager. This allows me to assign the same sound to millions of buttons that require the same sound, but it gives me the ability to have a specific sound for one button if I want.
null-coalessing null to specifiedUISound, null, audioUIManager - . , , :
specifiedUISound = specifiedUIsound == null ? audioUIManager.genericUISound : specifiedUISound;
? ?
: , specifiedUISound. ( public [SerializeField]). - , ?