Question: I want to change `Reference Resolutuion` with C# script in real time game, how can I make it?

[![st](https://i.stack.imgur.com/Vpszx.png)](https://i.stack.imgur.com/Vpszx.png)

Because I want to scale my controls with easiest way

[![enter image description here](https://i.stack.imgur.com/ZXxoA.png)](https://i.stack.imgur.com/ZXxoA.png)
[![enter image description here](https://i.stack.imgur.com/cXRG3.png)](https://i.stack.imgur.com/cXRG3.png)

Answer: 
Like all the other properties of [`CanvasScaler`](https://docs.unity3d.com/2018.3/Documentation/ScriptReference/UI.CanvasScaler.html) you can simply use the [`CanvasScaler.referenceResolution`](https://docs.unity3d.com/2018.3/Documentation/ScriptReference/UI.CanvasScaler-referenceResolution.html) property in a script like

```
GetComponent<CanvasScaler>().referenceResolution = new Vector2(xSize, ySize);

```
> 
> UI Scale Mode: `Constant Pixel Size`
> 
> 
> 

Simple template:

```
public class Scale : MonoBehaviour {

    public float scale = 1f; // 1 by default

    public void Update()
    {
        GetComponent<Canvas>().scaleFactor = scale;
    }
}

```