Skip to main content

Adding Plugin to a Unity Project

Learn how to add the GamePush plugin to your Unity project.

tip

The latest version of the plugin can be downloaded under the link.

The plugin works on Unity versions 2020 and higher.

Adding game to GamePush control panel

Before you start installing the GamePush plugin into your Unity project:

  1. Add a game in GamePush control panel.
  2. Click the Add game button.
  3. Go to the new window and give a name to the game and click Add Game button. After that you will get to the project interface. To add a project in Unity you will need: Project ID and Public Key.

  1. Copy the Project ID and Public Key to add them to your Unity project later.

Adding GamePush plugin to Unity

  1. Go to plugin Github and download the latest version of the plugin.

  1. To start working with GamePush plugin in Unity, add it in the standard way like other packages and assets. In the top menu of Unity Assets -> Import package -> Custom Package. Select the unitypackage of the plugin you downloaded earlier.

  2. In a new window, Unity will prompt you to import the contents of the package. Click Import and wait for the process to finish. If everything is done correctly, the GamePush folder will appear in the Project window together with other project files.

  3. Once the GamePush plugin has been added, you can use the plugin modules in the project.

Using GamePush modules

Work with the plugin is done through modules, each of which is responsible for a separate functionality. All plugin modules are used from scripts.

To work with modules:

  1. Add the GamePush library via using GamePush.

  2. Refer to the desired module. The name of all modules starts with GP.

  1. To work correctly with the plugin, you must wait for its initialization before calling its methods. There is GP_Init module for this purpose.
using UnityEngine;
// Add GamePush Library
using GamePush;

public class TestScript : MonoBehaviour
{
// You can subscribe to the GP_Init.OnReady event
private void OnEnable()
{
GP_Init.OnReady += OnPluginReady;
}

// You can wait for readiness via await GP_Init.Ready
private async void Start()
{
await GP_Init.Ready;
OnPluginReady();
}

// You can check the readiness via GP_Init.isReady
private void CheckReady()
{
if(GP_Init.isReady)
{
OnPluginReady();
}
}

private void OnPluginReady()
{
Debug.log("Plugin ready");
}
}

Rewarded ad example (GP_Ads module)

using UnityEngine;

// Add GamePush Library
using GamePush;

public class AdsManager : MonoBehaviour
{
// Subscribe to the GP_Ads.OnRewardedReward event;
private void OnEnable()
{
GP_Ads.OnRewardedReward += OnRewarded;
}

private void OnDisable()
{
GP_Ads.OnRewardedReward -= OnRewarded;
}

// When calling the method, you can specify any text value
// For example: COINS or GEMS
private void ShowRewarded(string idOrTag)
{
GP_Ads.ShowRewarded(idOrTag);
}

// If you successfully view Reward ads
// you can give a reward by checking the specified value:
private void OnRewarded()
{
if (idOrTag == "COINS")
Player.AddCoins(250);

if (idOrTag == "GEMS")
Player.AddGems(15);
}
}

Configuring Unity project for building WebGL

To build a project for web platforms, you need to switch the target platform to WebGL in the Build Settings (if you do not have WebGL in the list of platforms, install the appropriate module for your version of Unity)

  1. In the Unity project, open: Tools -> GamePush.

  2. Specify the Project ID and Public Token of your project that you copied from the GamePush control panel.

in the GamePush control panel:

in the Unity project Project ID and Token:

  1. If you want to show ads immediately when opening the game, then check Show Preloader Ad.

  2. If you want to call the GameReady event automatically, specify the call delay in milliseconds in the Gameready autocall delay field. For example, for a 2-second delay (the Unity splash screen), specify 2000.

  3. After filling in the fields Project ID, Token and additional settings, click Save.

  4. Now you can run a build, with any WebGL template.

Useful information

To check if the ad is installed correctly:

In the Unity editor, stubs are substituted with the output of the necessary information in the Console. They look like this:

If errors appear in the Unity editor as:

EntryPointNotFoundException: ...

These methods of the plugin are not stubbed, and to check all the functionality of the plugin, you need to create a Build game and check it on the right site or on the hosting.

If there are problems on mobile devices:

Use Unity version 2022.3 or later. Versions 2021 and earlier do not have official WebGL support for mobile devices, and early versions of 2022 have issues with some mobile browsers.

If the project is not building or the game is loading endlessly:

Check the path of the project and its folders for non-English letters. The same with the name of the archive and folders in it - non-English letters, spaces and special characters can cause endless loading of the game.

The project uses WEBGL Template:
https://github.com/greggman/better-unity-webgl-template

The plugin inherits the hierarchy and naming convention from sdk, you can refer to the documentation for more information about methods work.

Repository link: https://github.com/GamePushService/GamePush-Unity-plugin

Methods list: https://github.com/GamePushService/GamePush-Unity-plugin/tree/main/Demo/Assets/Plugins/GamePush/Runtime/Modules

Author: @Dinar_Shagidullin

GamePush Community (Telegram): @gs_community

We wish you success!

Stay in Touch

Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.

GamePush Community Telegram: @gs_community.

For your suggestions e-mail: [email protected]

We Wish you Success!