Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
顺
顺职VR迷宫游戏教学
Project
Project
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨泽宇
顺职VR迷宫游戏教学
Commits
df660829
Commit
df660829
authored
Feb 28, 2024
by
杨泽宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新
parent
6c4eae35
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
4777 additions
and
884 deletions
+4777
-884
2_Maze2.unity
Assets/_Scenes/2_Maze2.unity
+4595
-884
GameSystem.cs
Assets/_Scripts/GameSystem.cs
+1
-0
MathGame.cs
Assets/_Scripts/MathGame.cs
+162
-0
MathGame.cs.meta
Assets/_Scripts/MathGame.cs.meta
+11
-0
UI.meta
Assets/_预设/UI.meta
+8
-0
No files found.
Assets/_Scenes/2_Maze2.unity
View file @
df660829
This diff is collapsed.
Click to expand it.
Assets/_Scripts/GameSystem.cs
View file @
df660829
...
...
@@ -32,6 +32,7 @@ public class GameSystem : MonoBehaviour
private
void
Update
()
{
UpdateTimeText
();
if
(!
isPauseGame
)
{
currentTime
-=
Time
.
deltaTime
;
...
...
Assets/_Scripts/MathGame.cs
0 → 100644
View file @
df660829
using
UnityEngine
;
using
UnityEngine.UI
;
using
TMPro
;
using
System.Collections
;
public
class
MathGame
:
MonoBehaviour
{
[
Tooltip
(
"问题"
)]
public
TMP_Text
questionText
;
[
Tooltip
(
"答案"
)]
public
TMP_Text
answerText
;
[
Tooltip
(
"倒计时文本"
)]
public
TMP_Text
countdownText
;
[
Tooltip
(
"倒计时时长"
)]
public
float
countdownDuration
=
10f
;
[
Tooltip
(
"错误机会数量"
)]
public
int
chances
=
3
;
// 初始错误机会数量
[
Tooltip
(
"错误机会文本"
)]
public
TMP_Text
chancesText
;
private
int
num1
;
private
int
num2
;
private
char
operation
;
private
int
correctAnswer
;
private
bool
isAnswered
=
false
;
private
Coroutine
countdownCoroutine
;
void
Start
()
{
GenerateQuestion
();
countdownCoroutine
=
StartCoroutine
(
StartCountdown
());
}
/// <summary>
/// 倒计时协程
/// </summary>
/// <returns></returns>
IEnumerator
StartCountdown
()
{
float
timer
=
countdownDuration
;
while
(
timer
>
0f
)
{
yield
return
new
WaitForSeconds
(
1f
);
timer
-=
1f
;
countdownText
.
text
=
timer
.
ToString
();
}
if
(!
isAnswered
)
{
Debug
.
Log
(
"时间到!"
);
// 处理时间到的情况,例如重新生成问题
GenerateQuestion
();
ReduceChances
();
// 减少错误机会
}
}
/// <summary>
/// 生成问题
/// </summary>
private
void
GenerateQuestion
()
{
// 检查错误机会是否大于零
if
(
chances
<=
0
)
{
Debug
.
Log
(
"没有机会了!"
);
return
;
}
// 生成两个随机数(1-9)
num1
=
Random
.
Range
(
1
,
10
);
num2
=
Random
.
Range
(
1
,
10
);
// 随机选择一个操作符
int
opIndex
=
Random
.
Range
(
0
,
4
);
switch
(
opIndex
)
{
case
0
:
operation
=
'+'
;
correctAnswer
=
num1
+
num2
;
break
;
case
1
:
operation
=
'-'
;
correctAnswer
=
num1
-
num2
;
break
;
case
2
:
operation
=
'*'
;
correctAnswer
=
num1
*
num2
;
break
;
case
3
:
operation
=
'/'
;
correctAnswer
=
num1
/
num2
;
break
;
}
// 显示问题
questionText
.
text
=
num1
+
" "
+
operation
+
" "
+
num2
+
" = "
;
answerText
.
text
=
""
;
// 重置倒计时
if
(
countdownCoroutine
!=
null
)
{
StopCoroutine
(
countdownCoroutine
);
countdownCoroutine
=
StartCoroutine
(
StartCountdown
());
}
}
/// <summary>
/// 判断答案是否正确
/// </summary>
/// <param name="userAnswer"></param>
public
void
CheckAnswer
()
{
if
(
answerText
.
text
==
correctAnswer
.
ToString
())
{
Debug
.
Log
(
"正确"
);
isAnswered
=
true
;
if
(
countdownCoroutine
!=
null
)
{
StopCoroutine
(
countdownCoroutine
);
// 停止倒计时
}
}
else
{
Debug
.
Log
(
"错误"
);
ReduceChances
();
// 减少错误机会
}
}
/// <summary>
/// 减少错误机会数量并更新显示
/// </summary>
private
void
ReduceChances
()
{
chances
--;
UpdateChancesText
();
}
/// <summary>
/// 更新错误机会数量的显示
/// </summary>
private
void
UpdateChancesText
()
{
chancesText
.
text
=
"Chances: "
+
chances
;
}
/// <summary>
/// 点击回答按钮
/// </summary>
/// <param name="digit"></param>
public
void
AddDigit
(
int
digit
)
{
answerText
.
text
+=
digit
;
}
/// <summary>
/// 点击清除答案按钮
/// </summary>
public
void
ClearAnswer
()
{
answerText
.
text
=
""
;
}
}
Assets/_Scripts/MathGame.cs.meta
0 → 100644
View file @
df660829
fileFormatVersion: 2
guid: b022b0de637b910419cf476823b21fb3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/_预设/UI.meta
0 → 100644
View file @
df660829
fileFormatVersion: 2
guid: 68690a60723f9704e9ab39534de6dd86
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
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