Skip to content

Game

The CrazyEvents folder exposes a CrazyEvents class that is available anywhere in your code. Import it with using CrazyGames; or prefix the usage with CrazyGames A demo is available in the CrazyEventsDemo folder, you can run the scene and look at the outputs in your console. You can also see the SDK usage in the DemoAssets/ButtonActions.cs file.

This feature lets you share the Crazygames version of your game to the players and invite them to join a multiplayer game. You can call InviteLink with parameters that correspond to your game or game room.

Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("roomId", "1234");
string inviteLink = CrazyEvents.Instance.InviteLink(parameters);

We provide a helper if you want to automatically copy the invite link to the clipboard.

CrazyEvents.Instance.CopyToClipboard(inviteLink);

You can check if the user is currently playing through an invite link with IsInviteLink.

bool isInviteLink = CrazyEvents.Instance.IsInviteLink();

Finally, you can retrieve parameters passed through the invite link with GetInviteLinkParameter.

string roomId = CrazyEvents.Instance.GetInviteLinkParameter("roomId");

Here is a full example of this feature.

using CrazyGames;

if (CrazyEvents.Instance.IsInviteLink()) {
    string roomId = CrazyEvents.Instance.GetInviteLinkParameter("roomId");
    if (roomId != null && roomId != "") {
        Debug.Log(string.Format("Correct invite url, the roomId is {0}", roomId));
    } else {
        Debug.Log("Cannot find 'roomId' parameter");
    }
} else {
    Debug.Log("User is not playing through an invite link");
}

Gameplay

We provide functions that enable us to track when and how users are playing your games. These can be used to ensure our site does not perform resource intensive actions while a user is playing. The GameplayStart function has to be called whenever the player starts playing or resumes playing after a break (menu/loading/achievement screen, game paused, etc.). The GameplayStop function has to be called on every game break (entering a menu, switching level, pausing the game, ...) don't forget to call GameplayStart when the gameplay resumes.

using CrazyGames;

// Main menu, user clicks start
CrazyEvents.Instance.GameplayStart();
// Level is over, displaying switching level screen
CrazyEvents.Instance.GameplayStop();
// Next level starts
CrazyEvents.Instance.GameplayStart();
// The player is pausing the game by looking into the menu
CrazyEvents.Instance.GameplayStop();
// The player closes the menu and gets back to the game
CrazyEvents.Instance.GameplayStart();

Happy time

You can call the HappyTime function on player achievements, it will possibly adapt the website to celebrate!

Info

Use this feature sparingly, the celebration should remain a special moment.

// Player beats a boss, reaches a high score, etc.
CrazyEvents.Instance.HappyTime();

// Player finishes a level, gets an item, etc.
// No need to celebrate

Invite button

This feature allows you to display a button in the game footer, that opens a popup containing the invite link. The returned link is similar to the link returned from Invite link.

The invite button should only be used to invite players to a multiplayer gaming session. Please avoid using it for other use cases, such as a "Share" button for example, as this may lead to delayed submission check or even game rejection.

Invite button

Invite popup

You can show the invite button like this:

var parameters = new Dictionary<string, string>();
parameters.Add("roomId", "1234");
var inviteLink = CrazyEvents.Instance.ShowInviteButton(parameters);

Don't forget to hide the invite button when it is no longer necessary:

CrazyEvents.Instance.HideInviteButton();