Hello, I need help for my game. I guess all of you know games, if the player completes a level and he goes back to menu and press play he plays the next level and not the level which he has completed. I wanna make these system but I don’t know how. So I hope here is someone who can help me.
Here is my Player script:
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;
using TMPro;
using UnityStandardAssets.CrossPlatformInput;
public class Player : MonoBehaviour
{
[SerializeField] SpriteRenderer playerImage;
[SerializeField] TMP_Text playerNameText;
[SerializeField] ParticleSystem konfettiFx;
public float speed = 1f;
Rigidbody2D rb;
bool isMoving = false;
float x, y;
public GameObject completeLevelUI;
void Start()
{
rb = GetComponent<Rigidbody2D> ();
ChangePlayerSkin();
}
void ChangePlayerSkin()
{
Character character = GameDataManager.GetSelectedCharacter();
if (character.image != null)
{
playerImage.sprite = character.image;
playerNameText.text = character.name;
}
}
void Update()
{
x = CrossPlatformInputManager.GetAxis("Horizontal");
y = CrossPlatformInputManager.GetAxis("Vertical");
isMoving = (x != 0f || y != 0f);
}
void FixedUpdate()
{
if (isMoving)
{
rb.position += new Vector2(x, y) * speed * Time.fixedDeltaTime;
}
}
void OnCollisionEnter2D (Collision2D other)
{
string tag = other.collider.tag;
if (tag.Equals ("Coins"))
{
GameDataManager.AddCoins(25);
GameSharedUI.Instance.UpdateCoinsUIText();
Destroy(other.gameObject);
}
if (tag.Equals("finish"))
{
completeLevelUI.SetActive(true);
konfettiFx.Play();
}
}
}
and here is my SceneController script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public static class SceneController
{
static int mainScene = 0;
static int sceneToContinue;
public static void LoadMainScene ()
{
SceneManager.LoadScene(0);
}
public static void LoadNextScene ()
{
int currentScene = SceneManager.GetActiveScene().buildIndex;
if (currentScene < SceneManager.sceneCountInBuildSettings)
SceneManager.LoadScene(currentScene + 1);
}
public static void LoadPreviousScene()
{
int currentScene = SceneManager.GetActiveScene().buildIndex;
if (currentScene > 0)
SceneManager.LoadScene(currentScene - 1);
}
public static void LoadScene(int index)
{
if (index >= 0 && index < SceneManager.sceneCountInBuildSettings)
SceneManager.LoadScene(index);
}
}