Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Last active February 10, 2019 18:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unity3dcollege/80fbe9961489e53c3ea0d9afce172024 to your computer and use it in GitHub Desktop.
Save unity3dcollege/80fbe9961489e53c3ea0d9afce172024 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Analytics;
public class MyGameNameHereAnalytics : MonoBehaviour
{
private void Start()
{
DontDestroyOnLoad(this.gameObject);
LevelController.OnLevelComplete += LevelController_OnLevelComplete;
PlayerController.OnPlayerDied += PlayerController_OnPlayerDied;
}
private void PlayerController_OnPlayerDied(Vector3 deathPosition, IEnemy killedBy)
{
Dictionary<string, object> data = new Dictionary<string, object>();
data.Add("Position", deathPosition);
data.Add("KilledBy", killedBy.Name);
Analytics.CustomEvent("PLAYER_DIED", data);
}
private void LevelController_OnLevelComplete(string levelName)
{
Analytics.CustomEvent("LEVEL_COMPLETE:" + levelName);
}
private void OnDestroy()
{
Analytics.FlushEvents();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment