Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Im working on 2 D platfomer in UNity using C# . I created a levelmanager script to load each level and save player progress. However,
Im working on D platfomer in UNity using C# I created a levelmanager script to load each level and save player progress. However, im now trying to add a checkpoint system, with the last cehckpoint activated also saved. Heres my levelmanager code so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LevelManager : MonoBehaviour
declare levelsUnlocked
int levelsUnlocked;
declare checkpointsUnlocked
int checkpointsUnlocked;
holds the transform value
public Vector lastCheckPointActivated;
declare boolean levelWon and set to false
bool levelWon false;
need fixing a placeholder value
int playerStartPos ;
levelWon function
public void levelIsWon
set levelWon to true
levelWon true;
start function
void Start
sets levelsUnlocked to integer stored in Player preferences. If no int is stored the value is
levelsUnlocked PlayerPrefs.GetIntlevelsUnlocked;
check last checkpoint unlocked.If no integer is store set equal to
checkpointsUnlocked PlayerPrefs.GetIntcheckpointsUnlocked;
calls levelLoad function to load the level indicated by levelsUnlocked
levelLoad;
checkpointLoad;
loadLevel function
public void loadLevelint levelNum
load the level
SceneManager.LoadScenelevelNum;
update function
void Update
if levelWon equals true
if levelWon true
checkpointsUnlocked ;
and if levelsUnlocked is less than
if levelsUnlocked
increment levelsUnlocked by one
levelsUnlocked;
save new value to levelsUnlocked
PlayerPrefs.SetIntlevelsUnlocked levelsUnlocked;
set checkpoint to
PlayerPrefs.GetIntcheckpointsUnlocked;
else if levelsUnlocked
load the credits scene
SceneManager.LoadScene;
sets levelWon back to false
levelWon false;
level load function
void levelLoad
if levelsUnlocked is less than or equal to
if levelsUnlocked
load level
SceneManager.LoadScene;
else if levelsUnlocked equals
else if levelsUnlocked
load level
SceneManager.LoadScene;
else if levelsUnlocked equals
else if levelsUnlocked
load level three
SceneManager.LoadScene;
else if levelsUnlcoked equals
else if levelsUnlocked
load level
SceneManager.LoadScene;
else if levelsUnlocked equals
else if levelsUnlocked
load level five
SceneManager.LoadScene;
else if levelsUnlocked equals
else if levelsUnlocked
load level six
SceneManager.LoadScene;
else if levelsUnlocked equals
else if levelsUnlocked
load level seven
SceneManager.LoadScene;
else if levelsUnlocked equals
else if levelsUnlocked
load level eight
SceneManager.LoadScene;
else if levelsUnlocked equals
else if levelsUnlocked
load level nine
SceneManager.LoadScene;
void checkpointLoad
if checkpointsUnlocked equals
if checkpointsUnlocked
player starts at beginning of level
playerStartPos ;
if checkpointsUnlocked equals
else if checkpointsUnlocked
player starts at checkpoint
if checkpointsUnlocked equals
else if checkpointsUnlocked
player position is at checkpoint
else if checkpointsUnlocked equals
else if checkpointsUnlocked
player position is at checkpoint
else if checkpointsUnlocked equals
else if checkpointsUnlocked
player pos is at checkpoint
Here is my checkpoint code thus far:
public class Checkpoint : MonoBehaviour
private LevelManager lm;
void onTriggerEnterDColliderD other
if player collides w
Im a litle rusty so any guidance would be appreciated
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started