I'm developing a simple android app that needs to use the microphone. I'm able to load my app on my Android phone using developer mode, but I do not understand how to enable the mic. How can I enable the microphone and use the input?
I started with a brand new Unity 2D project. I created a TextMeshPro Text object to display logs and set this reference on the script via the inspector. I have attached the following script to the Main Camera.
using UnityEngine;
using UnityEngine.Android;
using TMPro;
public class RequestPermissionScript : MonoBehaviour
{
public TextMeshProUGUI logs;
void Start()
{
if (Permission.HasUserAuthorizedPermission(Permission.Microphone))
{
// The user authorized use of the microphone.
logs.text = "has authorized";
}
else
{
// We do not have permission to use the microphone.
// Ask for permission or proceed without the functionality enabled.
logs.text = "has not authorized";
Permission.RequestUserPermission(Permission.Microphone);
}
}
}
I then Build and Run this as Android and the app is loading on my Android phone attached via USB.
I expect a pop-up to appear asking for permissions to the mic, but this does not happen and the logs says "has not authorized". What am I missing or doing wrong?