Hello,
I am using unity version 2020.3.35f1 and whenever I load from my first scene to the next(
via code or mannually) the first scene overwrites the second.
The first scene is only some UI:
Where I have this code attached to the Onclick of the “Generate” button:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Submit : MonoBehaviour
{
public GameObject Width;
public GameObject Height;
public GameObject WidthError;
public GameObject HeightError;
public void Enter()
{
init();
int width;
int height;
if (!GetInput(out width, out height)) return;
SceneManager.LoadScene("Play");
}
void SetMapDimenseions(int width, int height)
{
var Map = GameObject.Find("BaseMap");
Map.transform.localScale = new Vector3(width,height);
}
void init()
{
Width = GameObject.Find("Width Input");
Height = GameObject.Find("Height Input");
WidthError = GameObject.Find("Invalid Width");
HeightError = GameObject.Find("Invalid Height");
WidthError.GetComponent<Text>().enabled = false;
HeightError.GetComponent<Text>().enabled = false;
}
bool GetInput(out int width, out int height)
{
var res = true;
try
{
var widthText = Width.GetComponentInChildren<Text>().text;
width = int.Parse(widthText);
}
catch
{
WidthError.GetComponent<Text>().enabled = true;
height = -1;
width = -1;
res = false;
}
try
{
var heightText = Width.GetComponentInChildren<Text>().text;
height = int.Parse(heightText);
}
catch
{
HeightError.GetComponent<Text>().enabled = true;
height = -1;
width = -1;
res = false;
}
return res;
}
}