How do I reset my game but keep the Player in the same position?
So, I'm creating a simple game that is really similar to Flappy Bird. Most of the game is already created but I'm stuck now. I want that when the bird hits the pipes, the level resets. The thing is I want a smooth reset in a way that it seems the only thing that changed was that the next pipes disappeared. What I'm trying to say is that I want to reset the level but keep the bird position. Can someone help me? I'm using:
Application.LoadLevel(Application.loadedLevel);
to reset the game.
Edit: I only want to keep the "Y position" of course, I want the "X position" to reset
Answer by Ali-hatem · Apr 21, 2016 at 09:13 PM
make empty game object & attach this script to it :
public class Data : MonoBehaviour {
public static Data dat; //class static so enter without getcomponent from other scripts
public Vector3 BirdPosition;
void Awake ()
{
if (dat == null)
{
DontDestroyOnLoad(gameObject);// game object will not be destroyed on scene reload
dat = this;
}
else if (dat != this)
{
Destroy(gameObject);
}
}
}
now from Bird script :
void Start(){
transform.position = new Vector3 (transform.position.x,Data.dat.BirdPosition.y,transform.position.z);
}
void Update(){
Data.dat.BirdPosition = transform.position;
}
Your answer
Follow this Question
Related Questions
reloading a scene after death - resetting scripts 1 Answer
R key= reset 3 Answers
How Checkpoint works? 1 Answer
How Can I Reset Values?(Unity3D) 0 Answers
Resetting Power up bar 0 Answers