Experiment API
The Experiment API enables you to get the assigned variation of an experiment. Use this API if you have a script/component that cannot be used with any Elecular Component.
In this example, we will create a simple player component that performs an attack when you press the Spacebar, and add a variation to that attack.
using Elecular.API;
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField]
private Experiment experiment;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Attack();
}
}
private void Attack()
{
Debug.Log("I am doing a standard attack!");
}
}You will notice that the component has an Experiment variable. You can drag and drop an experiment in the inspector field. If you have not created an experiment yet, you can follow the Quick Start tutorial.
Now we can access the assigned variation and modify the player's behavior as needed.
In some instances, it is more convenient to access a setting of the assigned variation.
When getting the assigned variation or setting from an experiment, we strongly recommend implementing an OnError callback. This callback is triggered whenever there is a problem connecting to the Elecular servers. This usually happens when the player is not online. In these cases, you can simply default to normal behaviour.
Last updated
Was this helpful?