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.

Setup

Open the Public Zone in the game you want:

In the Unity project, open:

Edit > Project Settings > Player > Resolution and Presentation

Select WebGL Template - GamePush and fill:

Project id and Public Token of your project as on the screenshot:

If you want to show ads immediately when you open the game, then in the field:
Show Preloader Ad set true

tip

Open the GamePush folder and drop Prefab GameScoreSDK into the project Hierarchy.

Prefab can be dropped on the initial scene, the prefab will not be deleted when changing scenes

Rewarded ad example

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);
}
}

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.

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

In the folder:
Assets/WebGLTemplates/GameScore/logo.png
You can change the logo to your own, it will be displayed when loading.

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://gitlab.com/shagidullin/gamepush_unity

Methods list: https://gitlab.com/shagidullin/gamepush_unity/-/tree/master/GS%20Unity%20-%20Demo/Assets/GameScore/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!