- Home /
How to move back and forth between scenes with the original scene changing?
New to Unity, building a 2d game. I have two scenes connected through buttons. From scene 1 I can click to scene 2 and from scene 2 I can then click back to scene 1. My question is when I click from scene 2 back to scene 1 I would like the button in scene 1 to have moved positions. Any thoughts on achieving this?
Answer by aditya · Nov 19, 2016 at 06:50 AM
Singleton pattern is your key ... create a gameobject and attach a script to it and paste this in that script
[HideInInspector]
public static singletonClass instance;
void Awake(){
if (instance == null) {
DontDestroyOnLoad (gameObject);
instance = this;
} else if (instance != this) {
Destroy (gameObject);
}
}
now this gameobject will not be deleted while switching scenes, this means any script on it will also not be deleted ... now just a basic example for your situation could be a new script on this gameobject and this script holds a position for your button so on load of scene1 read position from this script and assign to your button and on clicking on button in scene 1 just write a new position
Accept if it helps
Your answer
Follow this Question
Related Questions
Why do I have to double click on a button the first time? 4 Answers
Moving Player Left/Right with Buttons 2 Answers
continous movement for rigidbody2d using addforce with buttons 2 Answers
Touchscreen Movement on buttons 1 Answer
Can not click buttons in the animator (2d),Can not click buttons in the animator 0 Answers