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.

circle-info

We can create customized Elecular components for your custom Unity Components if needed. Please contact us.

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.

triangle-exclamation

Last updated