How to ask runtime permissions for Camera in unity?

Viewed 1606

I need a C# script, in case the user refuses permission, a message appears that he must go to the settings in order to allow the permission the overloaded image here enter image description here

1 Answers

If you try searching a bit on the Google or in Unity Docs, you'll find Requesting Permissions article. I would suggest you to go through the complete documentation to get the better idea.

However, to make things easy, you can refer to below code:

using UnityEngine;
#if UNITY_ANDROID
using UnityEngine.Android;
#endif

void CheckCameraPermission()
{
    #if UNITY_IOS
        if (!Permission.HasUserAuthorizedPermission(Permission.Camera)) {
            // PERMISSION NOT AVAILABLE ON IOS, DISPLAY POPUP MESSAGE
        }
    #endif
    #if UNITY_ANDROID
        if (!Permission.HasUserAuthorizedPermission(Permission.Camera)) {
            // PERMISSION NOT AVAILABLE ON ANDROID, DISPLAY POPUP MESSAGE
        }
    #endif
}

I hope that answers your question.

Related