When the resolution is changed, what method will be called?

I assume you’re looking for an event or callback you can handle when the user resizes Unity’s window. The bad news is that there isn’t one. Read replies in the following forum thread:

http://forum.unity3d.com/threads/window-resize-event.40253/

Replies here suggest checking the resolution every frame to see if it has changed. This is inelegant, but as far as I know, there is no built-in event that is raised for this.

There’s sadly no callback for resolution changes.

If you’re in the browser, you can talk to the browser with JavaScript, as detailed here.

If the resolution is changed because the user clicks a button you made, just add the callback to that button.

Finally, if it’s outside your control, just make a method that polls Screen width and height frequently.

You can define an EventHandler in a Script:

1- Create a script with this:

using UnityEngine;
    
public class WindowManager : MonoBehaviour {

    public delegate void ScreenSizeChangeEventHandler(int Width, int Height);       //  Define a delgate for the event
    public event ScreenSizeChangeEventHandler ScreenSizeChangeEvent;                //  Define the Event
    protected virtual void OnScreenSizeChange(int Width, int Height) {              //  Define Function trigger and protect the event for not null;
        if (ScreenSizeChangeEvent != null) ScreenSizeChangeEvent(Width, Height);
    }

    private Vector2 lastScreenSize;
    public static WindowManager instance = null;                                    //  Singleton for call just one instance

    void Awake() {
        lastScreenSize = new Vector2(Screen.width,Screen.height);
        instance = this;                                                            // Singleton instance
    }

    void Update() {
        Vector2 screenSize = new Vector2(Screen.width, Screen.height); 

        if (this.lastScreenSize != screenSize) {
            this.lastScreenSize = screenSize;
            OnScreenSizeChange(Screen.width, Screen.height);                        //  Launch the event when the screen size change

        }
    }

}

2- Associate this script to any basic GameObject : (Main Camera for example)

3- Now You can consume the event anywhere:

    private void Start () {
        WindowManager.instance.ScreenSizeChangeEvent += Instance_ScreenSizeChangeEvent;
    }


    private void Instance_ScreenSizeChangeEvent(int Width, int Height) {
        Debug.Log("Screen Size Width = " + Width.ToString() + "  Height = " +  Height.ToString());
    }

Just use this:

int lastScreenWidth = 0;
int lastScreenHeight = 0;

void Update()
{
   if (lastScreenWidth != Screen.width || lastScreenHeight != Screen.height)
   {
      lastScreenWidth = Screen.width;
      lastScreenHeight = Screen.height;
      OnScreenSizeChanged(); //<--- create this function
}