question

Darius Vu avatar image
Darius Vu asked

How to execute the Azure Function directly from Unity Client?

Dear Team,

Do you know any way to execute the Azure function directly from Unity client (don't use automation rules in Playfab Manager) and pass the parameters such as an email and password to Azure function as inputs?

Thank you so much!

Account Managementgame manager
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Darius Vu avatar image
Darius Vu answered

This is the solution from Sarah Zhang. Thank you so much!!!

Unity clients can directly send a post request to execute the Azure Functions. You can send a POST request using UnityWebRequest.

Azure Function:

[FunctionName("HttpTriggerCSharp")]
public static async Task<dynamic> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log)
{
	log.LogInformation("C# HTTP trigger function processed a request.");
	// do the verifiction and resetting password here
	return new OkObjectResult("Please pass a name on the query string or in the request body");
        }
}


Unity code:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class confirmURL : MonoBehaviour
{
    public void OnClickButton()
    {
        StartCoroutine(Post());
    }
 
    IEnumerator Post()
    {
        WWWForm form = new WWWForm();

//add fields here
       
        form.AddField("name", "someone");

//Use your Azure Function URL here
        UnityWebRequest webRequest = UnityWebRequest.Post("http://xxxxxxxxxxxxx/api/HttpTriggerCSharp", form);
        yield return webRequest.SendWebRequest();
        
        if (webRequest.isHttpError || webRequest.isNetworkError)
            Debug.Log(webRequest.error);
        else
        {
            Debug.Log(webRequest.downloadHandler.text);
        }
    }
}
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.