How to use Analytics.CustomEvent?
Hi, I'm trying to set up my project with Unity Analytics (I'm in version 5.4.2, and using Javascript), and I've gotten stuck on using Analytics.CustomEvent. The documentation doesn't explain it too well (and not at all in javascript), and everything I try results in an error. Here is the function I'm trying to track:
function LoadLevel (lvl:int) {
SceneManager.LoadScene(lvl, LoadSceneMode.Single);
UnityEngine.Analytics.Analytics.CustomEvent("Level Loaded", new Dictionary());
}
When it compiles this, I get the error:
Assets/Scripts/Menu/MenuScript.js(30,73): BCE0005: Unknown identifier: 'Dictionary'.
I've searched and searched on this topic but most everything is either in c# or an older version of Unity. Is there something I have to import in order to use "Dictionary"?
Also, I don't really understand what a "Dictionary" is... I've searched the Unity documentation, but I can't find anything there. If anyone has a good understanding of what it is, I'd really appreciate a quick summary. Thanks in advance!
Answer by ap-unity · Jan 20, 2017 at 08:49 PM
You will need to add import System.Collections.Generic;
to the beginning of your script. This will allow you to use the Generic collection types (Dictionary, List, etc.)
You can find out more about Dictionaries (and Lists) in this tutorial. Their code examples are in C# and Javascript:
https://unity3d.com/learn/tutorials/modules/intermediate/scripting/lists-and-dictionaries