Agora provides an open-source API-Example-Unity sample project on GitHub. This document introduces how to run this project and experience a video call implemented by the Agora SDK.
Unity 2017 or later (the interface description in this article is based on Unity 2018.4.28f1).
Unity Hub 1.0.0 or later (the interface description in this article is based on Unity Hub 2.4.3).
Operating system and IDE requirements:
||Operating system version
||Android 4.1 or later
||Android Studio 3.0 or later
||iOS 9.0 or later
||Xcode 9.0 or later
||macOS 10.10 or later
||Xcode 9.0 or later
||Windows 7 or later
||Microsoft Visual Studio 2017 or later
A valid Agora account.
If your network has a firewall, follow the instructions in Firewall Requirements
to access Agora's services.
1. Create an Agora project
To create an Agora project, do the following:
- Enter the Project Management page.
- Click Create.
- Follow the on-screen instructions to enter a project name and use case, and check Secured mode: APP ID + Token (Recommended) as the authentication mechanism.
- Click Submit. You can now see the project on the Project Management page.
2. Get an App ID
Agora automatically assigns each project an App ID as a unique identifier.
To copy this App ID, find your project on the Project Management page in Agora Console, and click the icon in the App ID column.
The App ID is needed when you run the sample project.
3. Generate a temporary token
To ensure communication security, Agora recommends using tokens to authenticate users joining a channel.
For testing purposes, Agora Console supports generating RTC temporary tokens. To generate an RTC temporary token:
- On the Project Management page, find your project and click Config.
- Click Generate temp RTC token under Primary Certificate.
- Enter the name of the channel that you want to join, and click Generate. When joining the channel later, ensure that the channel name is the same with the one you enter here.
- Click the copy icon to copy the temporary token.
Temporary tokens are for demonstration and testing purposes only, and remain valid for 24 hours. In a production environment, you need to deploy your own server for generating tokens. For details, see Authenticate Your Users with Tokens
The temporary token is needed when you run the sample project.
4. Integrate the Agora SDK
Integrate the Agora SDK into the sample project, as follows:
- Download the Agora-Unity-Quickstart repository.
- Open Unity Hub, and go to the Installs panel. Click ADD to select a version of Unity, add the needed modules, and click DONE.
- After installation, go to the Projects panel. Click ADD to add the
Agora-Unity-Quickstart/API-Example-Unity sample project.
- On the project list, select a version of Unity, click API-Example-Unity, carefully read the message on the pop-up dialog, and click CONFIRM. The sample project opens in Unity.
- In Unity, go to the Asset Store panel, find the Agora Video SDK for Unity, and click Download to download the SDK.
- After downloading, click Import to open the Import Unity Package window.
- Click Import on the Import Unity Package window to import the SDK. Once the import is finished, you can see the
AgoraEngine folder on the Project panel.
5. Configure the sample project
- On the Project panel of Unity, open the
- Double-click MainScene, and then click VideoCanvas on the Hierarchy panel.
- On the Inspector panel, find the Hello Video Agora script. Enter the App ID of your Agora project, the temporary token generated in Agora Console, and the channel name that you used to generate the temporary token.
6. Start a video call
Connect your device, and run the sample project.
For example, when the sample project runs successfully on a macOS device, you can see the following interface.
If you want to experience a one-to-one video call, you can also use the Agora Web sample app to interact with your macOS device. Ensure that you enter the same App ID, channel name, and temporary token in the Agora Web sample app as in the API-Example-Unity sample app.
Sample project structure
See the code of the main functions in the
HelloVideoAgora.cs file of the sample project for your reference.
Agora also provides articles for running the sample project on different platforms as follows: