Sample: Reading Experiments and Groups

The varying values of Parameters and Elements should be read in, and functionality of the game should be driven by these values directly, meaning that very rarely should you write conditional code (e.g. if) based upon what the current Experiment or Experiment Group is.

However sometimes this is either unavoidable, or this information is otherwise useful. The PlayURPlugin singleton provides this information in the form the CurrentExperiment and CurrentExperimentGroup enums. For example, to display the current experiment or group on a text box:

using TMPro;
using PlayUR;

public class ReadExperimentAndGroup : PlayURBehaviour
{
    public TMP_Text txtExperiment, txtGroup;

    public override void OnReady()
    {
        txtExperiment.text = PlayURPlugin.instance.CurrentExperiment.ToString();
        txtGroup.text = PlayURPlugin.instance.CurrentExperimentGroup.ToString();
    }
}

Unity Sample Requirements

You can import this sample from the Unity Package Manager. For the code to run, you will need a game set up in Unity (see Getting Started), and the following configured for the game on the PlayUR Dashboard:

  • Experiments: At least one
  • Experiment Groups: At least one
In This Article
Back to top Generated by DocFX