Connect and sign in Unity
You can connect and sign in a single interaction from your Unity game.
Prerequisites
-
MetaMask SDK set up in your Unity game.
-
MetaMask Mobile version 7.10 or later. Your users must have an updated version of MetaMask Mobile for this feature to work correctly. For older versions of MetaMask, this function may not work as expected.
Steps
-
Open your Unity project with the SDK installed.
-
In your script, create a new function named
ConnectAndSign
:public void ConnectAndSign()
{
MetaMaskUnity.Instance.ConnectAndSign("This is a test message");
}Replace the test message with any string message you want to sign.
importantMake sure you initialize
MetaMaskUnity.Instance
before using this function. To do so, enable Initialize On Awake in the MetaMask Unity script inspector, or runMetaMask.Instance.Initialize()
. -
Call the
ConnectAndSign
function whenever you want to establish a connection and sign a message. For example, you can call this function when a button is clicked:public void OnButtonClick()
{
ConnectAndSign();
}