Home>

As a premise, I'm thinking of making a one-on-one match-up game.
What I want to achieve is that when the conclusion is reached, the two split screens will gradually expand and only the winning screen will be the one. The ideal would be:


The problem i am having

I was able to press the button to switch to only one screen, but I don't know how to gradually expand it to one screen.

Corresponding source code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController: MonoBehaviour
{

GameObject Cam2Obj;

private Camera Cam;
private Camera Cam2;

// Start is called before the first frame update
void Start ()
{
Cam = Camera.main;// 1P camera

Cam2Obj = GameObject.Find ("2PCamera");// 2P camera
Cam2 = Cam2Obj.GetComponent();
}

// Update is called once per frame
void Update ()
{
// Become a 1P only camera
if (Input.GetKey (KeyCode.E))
{

Cam.rect = new Rect (0.0f, 0.0f, 1.0f, 1.0f);
Cam2.rect = new Rect (0.0f, 0.0f, 1.0f, 0.0f);
}

// Only 2P camera
if (Input.GetKey (KeyCode.R))
{
Cam2.rect = new Rect (0.0f, 0.0f, 1.0f, 1.0f);
}

// The screen is split into two
if (Input.GetKey (KeyCode.T))
{
Cam.rect = new Rect (0.0f, 0.0f, 0.5f, 1.0f);
Cam2.rect = new Rect (0.5f, 0.0f, 0.5f, 1.0f);
}
}
}

What I tried

I thought I could do something like Cam.rect.width = + 0.1f, but I couldn't.

Supplementary information (FW/tool version, etc.)

The version of Unity is 2019.4.14f1.
Please let me know if there is any missing information.

  • Answer # 1

    Why not try using Mathf.Lerp () as well?

    As for how to use

    float x = 0.0;
    void Update () {
        x = Mathf.Lerp (x, 100, Time.deltaTime);
    }

    If you turn it with Update () like this, the process that x gradually changes from 0 to 100 is completed.
    After that, I wondered if I should add a process to stop the process when it reaches the target size.
    Time.deltaTime * Number
    You can also change the speed of change by writing.

  • Answer # 2

    [Unity] Split screen and multi-display How about referring to this article?
    I think that if you adjust the size of the camera after dividing it, you will get closer to what you want to do.