Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SSBookMinigames
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
SSBookMinigames
Commits
e94cf53a
Commit
e94cf53a
authored
Apr 12, 2026
by
Mahmoud Aglan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix challenge crash
parent
ac3d4138
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
ChallengeManager.cs
...sets/ScienceStreet/Features/Challenge/ChallengeManager.cs
+16
-10
No files found.
My project/Assets/ScienceStreet/Features/Challenge/ChallengeManager.cs
View file @
e94cf53a
...
...
@@ -37,6 +37,10 @@ public class ChallengeManager : MonoBehaviour
private
float
_lastGameTimeLeft
=
0f
;
public
float
LastGameTimeLeft
=>
_lastGameTimeLeft
;
// ✅ NEW: prevent double-start
private
bool
_challengeRunning
=
false
;
public
bool
IsChallengeRunning
=>
_challengeRunning
;
// ─── Singleton ────────────────────────────────────────────────────────
private
void
Awake
()
{
...
...
@@ -71,6 +75,9 @@ public class ChallengeManager : MonoBehaviour
// ─── Challenge flow ───────────────────────────────────────────────────
public
async
UniTask
StartChallenge
()
{
if
(
_challengeRunning
)
return
;
// prevent double-start
_challengeRunning
=
true
;
startTime
=
DateTime
.
UtcNow
;
currentGameIndex
=
0
;
timeSaved
=
0
;
...
...
@@ -83,20 +90,16 @@ public class ChallengeManager : MonoBehaviour
private
void
OnGameCompleted
(
bool
hasWon
,
float
timeLeft
,
float
pointsEarned
)
{
print
(
"Game completed"
);
if
(
currentGame
!=
null
)
currentGame
.
OnGameCompleted
-=
OnGameCompleted
;
if
(!
hasWon
)
{
LostChallenge
();
LostChallenge
()
.
Forget
()
;
return
;
}
// ✅ NEW: store timeLeft so the next game can use it as a bonus
_lastGameTimeLeft
=
timeLeft
;
// Add time left to total saved time
timeSaved
+=
Mathf
.
RoundToInt
(
timeLeft
);
currentGameIndex
++;
...
...
@@ -139,16 +142,19 @@ public class ChallengeManager : MonoBehaviour
private
async
UniTask
LostChallenge
()
{
Debug
.
Log
(
"Challenge failed."
);
challengeCanvas
.
ShowChallengeResult
(
false
,
0
,
penaltiesPerGame
[
currentGameIndex
]);
_challengeRunning
=
false
;
int
maxPenalty
=
penaltiesPerGame
[
currentGameIndex
];
int
currentPoints
=
UserService
.
Instance
.
CurrentUser
?.
Points
??
0
;
int
actualPenalty
=
Mathf
.
Min
(
maxPenalty
,
currentPoints
);
challengeCanvas
.
ShowChallengeResult
(
false
,
0
,
actualPenalty
);
await
ChallengeService
.
Instance
.
AddChallenge
(
false
,
0
,
-
penaltiesPerGame
[
currentGameIndex
]
,
startTime
,
DateTime
.
UtcNow
);
false
,
0
,
-
actualPenalty
,
startTime
,
DateTime
.
UtcNow
);
}
private
async
UniTask
WonChallenge
(
int
timeSaved
,
int
pointsEarned
)
{
Debug
.
Log
(
"Challenge completed! Total time saved: "
+
timeSaved
)
;
_challengeRunning
=
false
;
challengeCanvas
.
ShowChallengeResult
(
true
,
timeSaved
,
pointsEarned
);
await
ChallengeService
.
Instance
.
AddChallenge
(
true
,
timeSaved
,
pointsEarned
,
startTime
,
DateTime
.
UtcNow
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment