Sample: Reading Game Parameters

Parameters can be integers, floats, booleans, or strings. There are dedicated Get functions for each of these primative types.

using PlayUR;

public class SpawnBalls : PlayURBehaviour
{
    public GameObject prefabToSpawn;
    public Vector2 offset = new Vector2(1,0);

    public override void OnReady()
    {
        int count = PlayURPlugin.instance.GetIntParam("ball_count", defaultValue:5);

        Vector2 overallOffset = count/2f * offset + offset/2; 
        for (var i = 0; i < count; i++)
        {
            Instantiate(prefabToSpawn, (Vector2)transform.position + offset * i - overallOffset, Quaternion.identity); 
        }
    }
}

If a parameter has been set up as a list, you can request a list of values of a given type:

using PlayUR;

public class RandomItemFromList : PlayURBehaviour
{
    public override void OnReady()
    {
        string[] list = PlayURPlugin.instance.GetStringParamList("names");
        Debug.Log(list[Random.Range(0, list.Length)]);
    }
}

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
  • Parameters:
  • ball_count
  • names[] (note the []) on the end means PlayUR will treat it as a list on the Dashboard UI, and it can be read in as a list by the Unity Plugin
In This Article
Back to top Generated by DocFX