Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Get monitor that the game is running on

Discussion in 'Scripting' started by ArachnidAnimal, Jul 24, 2018.

  1. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    Is there a way to determine what monitor the game is currently running on (i.e. left or right)? I need to detect if the game window was moved to a different monitor.
    I don't see anything in https://docs.unity3d.com/ScriptReference/Screen.html regarding an ID#.

    Thanks.
     
  2. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,315
    Ryiah likes this.
  3. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    Windows does so much internal magic you basically cannot know. It's a huge nuisance. Best thing I've been able to do is make dropdowns that allow you to retarget cameras to different display id's and pray that windows populates them consistently.
     
  4. angelonit

    angelonit

    Joined:
    Mar 5, 2013
    Posts:
    40
    From version 2021.2.15 there is new functionality regarding this and you can use this to get the index of the screen your app is on:
    Code (CSharp):
    1.     public int GetCurrentDisplayNumber()
    2.     {
    3.         List<DisplayInfo> displayLayout = new List<DisplayInfo>();
    4.         Screen.GetDisplayLayout(displayLayout);
    5.         return displayLayout.IndexOf(Screen.mainWindowDisplayInfo);
    6.     }
    7.  
     
    CitrioN, mrVentures, _geo__ and 2 others like this.
  5. Jiaquarium

    Jiaquarium

    Joined:
    Mar 22, 2020
    Posts:
    40
    Bump. Is there any way to do this before v2021.2.2?

    I'm locked in on v2021.1 is the only problem.
     
    mrVentures likes this.