- Home /
Question by
DoomVegan · Jun 18, 2019 at 10:01 AM ·
c#variablesscene-loading
Members not reset with SceneManager.LoadScene(scene);
Hi, beginner programmer here. I thought it didn't matter where I initialize my variables, either in the member or method. However in Unity this does make a difference. When I reload the scene, the members are NOT reset but the methods are. StartX & StartY are not declared static anywhere in the code. I even tested by changing the variable startX to a unique variable name inside the class and it still changed when I used SceneManager.LoadScene(). Any ideas what I'm missing?
public class scIntro : MonoBehaviour
{
// This does NOT reset.
private int startX = (Screen.width / 2) ; //120 ;
private int spaceX = 115;
private int startY = (Screen.height / 2);
void Start()
{
// This resets.
startX = (Screen.width / 2) ; //120 ;
spaceX = 115;
startY = (Screen.height / 2);}
}
Comment