How to change the name of the game in the tray when it is running?

Hi all! If the game is running, it is possible to change its name, or even be the icon that is in the tray? While the application is not in focus (minimized), it continues to live his life as soon as there is an important event, you need to notify the user about it, such as a name change in the system tray, thank you!

Or how you can still make a notification to the user in another way?

P.S. Sorry my english i’m from russia

Unity API doesn’t expose such functionality, so you have to use Win32 API. So for ex., changing the window title would be something like this:

public class NewBehaviourScript : MonoBehaviour {

    [DllImport("user32.dll", CharSet = CharSet.Ansi)]
    public static extern IntPtr FindWindow(string strClassName, string strWindowName);

    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern bool SetWindowText(IntPtr hwnd, String lpString);

    private IntPtr windowHandle;

    private string title = "NotSet";


    // Use this for initialization
    void Start ()
    {
        windowHandle = FindWindow("UnityWndClass", Application.productName);
    }
   

    void OnGUI()
    {
        GUILayout.Label(windowHandle.ToString());
        title = GUILayout.TextField(title);
        if (GUILayout.Button("Set title for " + windowHandle.ToString()))
            SetWindowText(windowHandle, title);
    }
}

That helped! Thank you so much! I did not know about using user32, and how you can change the icon of the game?

Changing icon is more complex - see this c++ - How to change the icon in taskbar using windows api - Stack Overflow. You already have HWND, that means you would need to create HICON object.

It would be easier to create a native plugin in this case, but if you don’t know Win32 API, it will be quite a challenge for you.

Thank you! That helped!