This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

📢 preface

  • While working with Unity, you may encounter a needDual-screen display or multi-screen displayThe demand of
  • Simply put, you need to display the game on two or more monitors to achieve a different display effect
  • Now let’s do a simple double screen display to see the effect!

🍉 Display effect of multiple screens

🏳️🌈 Scenario construction, used to distinguish different screens

Let’s open Unity and create a new Scene

Then add a new Camera in the scene, and in the new Camera properties panel set it to Display2(default is Display1)

As shown below.Then, on any cube or sphere in the scene, adjust the position of the camera and the game object

It’s easy to distinguish between two screens later


🏳️🌈 adds two canvases to differentiate the display of different screens

Create a new canvasCanvasAdd either a Text component or a Button component. No additional Settings are required

Then add a Canvas, like the first one, with a Text or Button for display differentiation

thenTarget DisplaySet toDisplay2

In the Game view, I can toggle Display, and the two canvases I set up are shown below


🏳️🌈 activates other displays using codes

Once that’s done, it’s time to activate the extra display with code!

By default, there is only one monitor, so extra monitors need to be explicitly activated when running the program

You can do this with the display. Activate code. Note that you only need to Activate once, and once activated, you cannot deactivate the active state.

Display.displays.Length, in the Editor, has a value of 1 no matter how many displays are connected to your host.

Only when the package runs, the return value is really connected to the number of monitors, you can package the program to perform a try, will show the corresponding presence of the monitor!

Sample code:

using UnityEngine;

public class DisplayDemo : MonoBehaviour
{
    void Start()
    {
        // Loop through all existing screens
        for (int i = 0; i < Display.displays.Length; i++)
        {
            // Turn on the existing screen display and activate the monitor
            Display.displays[i].Activate();
            Screen.SetResolution(Display.displays[i].renderingWidth, Display.displays[i].renderingHeight, true); }}}Copy the code

Then hang the script in our instance scenario!


🏳️🌈 package as an EXE file and run it on the PC

Exe is easy to package, File -> Build Setting

And then clickPlayerSetting, just change the company name and package name

Add the current scene to the panel and clickBuildCan beThen select the address folder you want to save in the pop-up window and wait for Unity to pack and generate

Once you’ve finished packing, click the button as shown below.exe fileExecution can be

Then run the program and see what happensI have two screens here, so these two images are displayed on two screens, one on each side.


💬 summary

  • In practice, handling the content on these two screens is definitely not that simple
  • In real games, it may be necessary to have a dual-screen display for a good gaming experience, so this is sometimes used
  • Unity supports a maximum of 8 screens, so you wouldn’t normally use that many. It can also be used for multi-screen display in some bionic projects
  • That’s the end of this article, and learn a small operation!