So I’m changing scene from the Main Menu by doing a simple SceneManager.LoadScene(“Level1”) to load level1 and I’m using a script to fix the camera based on the screen resolution
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
public class CameraResFixer : MonoBehaviour
{
// Use this for initialization
void Start()
{
// set the desired aspect ratio, I set it to fit every screen
float targetaspect = 1920f / 1080f;
// determine the game window's current aspect ratio
float windowaspect = (float)Screen.width / (float)Screen.height;
// current viewport height should be scaled by this amount
float scaleheight = windowaspect / targetaspect;
// obtain camera component so we can modify its viewport
Camera camera = GetComponent<Camera>();
// if scaled height is less than current height, add letterbox
if (scaleheight < 1.0f)
{
Rect rect = camera.rect;
rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f - scaleheight) / 2.0f;
camera.rect = rect;
}
else // add container box
{
float scalewidth = 1.0f / scaleheight;
Rect rect = camera.rect;
rect.width = scalewidth;
rect.height = 1.0f;
rect.x = (1.0f - scalewidth) / 2.0f;
rect.y = 0;
camera.rect = rect;
}
}
void Update()
{
}
}
that’s the script I’m using.
After trying it I found out that instead of seeing a black background behind my game background I see the old menu screen, what’s weird is that the old menu disappears when I call the pause menu.
this is before I pause the game link: Imgur: The magic of the Internet
and this is how it looks after calling the pause script, link : Imgur: The magic of the Internet which is how I want it to look
There’s nothing weird in the pause script it’s just:
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (gamePaused)
{
Resume();
}
else
{
Pause();
}
}
}
public void Resume()
{
pauseMenu.SetActive(false);
Time.timeScale = 1;
gamePaused = false;
input.ActivateInput();
Cursor.visible = false;
}
public void Pause()
{
pauseMenu.SetActive(true);
Time.timeScale = 0;
gamePaused = true;
input.DeactivateInput();
Cursor.visible = true;
}
what am I missing? how do I unload or make the old scene background disappear?