游戏展示
游戏开发
创建 2D 游戏
略
设置分辨率 1280x720

InputField
- Hirearchy
- Create
- UI
- InputField
- UI
- Create

- Inspector
- Rect Transform
- Width:
700
- Height:
80
- Width:
- Rect Transform

Canvas
- Inspector
- Canvas
- Render Mode:
Screen Space - Camera
- Render Camera:
Main Camera
- Render Mode:
- Canvas Scaler(Script)
- UI Scale Mode:
Scale With Screen Size
- Reference Resolution
- X:
1280
- Y:
720
- X:
- Match:
0.5
- UI Scale Mode:
- Canvas

InputField > Text
- Inspector
- Text(Script)
- fontSize:
60
- fontSize:
- Paragraph
- Alignment:
center
- Alignment:
- Text(Script)
InputField > Placeholder
- Inspector
- Text(Script)
- Text:
Enter Your Guess
- Text:
- Paragraph
- Alignment:
center
- Alignment:
- Text(Script)

Text
Hirearchy
- Canvas
- Create
- Text
- Create
- Canvas
Inspector
- Rect Transform
- Pos X: 0
- Pos Y:
218
- Width:
700
- Height:
80
- Text(Script)
- Text:
Guess A Number Between 0 And 100
- Text:
- Paragraph
- Alignment:
center
- Alignment:
- Rect Transform
Camera
- Inspector
- Camera
- Background:
Black
- Background:
- Camera


Button
Hirearchy
- Canvas
- Create
- Text
- Create
- Canvas
Inspector
- Text(Script)
- Text:
Guess
- Text:
- Text(Script)
Button -> Text
- Inspector
- Rect Transform
- Pos X: 0
- Pos Y:
-162
- Width:
300
- Height:
108
- Rect Transform

GuessTheNumberScript
- Project
- Create
- Folder:
Scripts
- Folder:
- Scripts
- Create
- C# Script:
GuessTheNumberScript
- C# Script:
- Create
- Create

1 | using System.Collections; |
2 | using System.Collections.Generic; |
3 | using UnityEngine; |
4 | using UnityEngine.UI; |
5 | |
6 | public class GuessTheNumberScript : MonoBehaviour |
7 | { |
8 | public InputField input; |
9 | public Text infoText; |
10 | private int guessNumber; |
11 | private int userGuessNumber; |
12 | |
13 | void Start() |
14 | { |
15 | guessNumber = Random.Range(0, 100); |
16 | } |
17 | |
18 | public void CheckGuess() |
19 | { |
20 | userGuessNumber = int.Parse(input.text); |
21 | |
22 | if (userGuessNumber == guessNumber) |
23 | { |
24 | infoText.text = "You Guessed The Number! You Are A Wizard"; |
25 | } |
26 | else if (userGuessNumber > guessNumber) |
27 | { |
28 | infoText.text = "Your Number Is Greater Than The Guess Number"; |
29 | } |
30 | else |
31 | { |
32 | infoText.text = "Your Number Is Lower Than The Guess Number"; |
33 | } |
34 | |
35 | input.text = ""; |
36 | } |
37 | } |
GameController
- Hirearchy
- Create Empty:
GameController
- Create Empty:
添加 GuessTheNumberScript
到 GameController

On Click
Button
- Inspector
- On Click()
- 添加:
GameController
- 选择:
GuessTheNumberScript.CheckGuess
- 选择:
- 添加:
- On Click()

导出游戏
- File
- Build Settings (Shift + Cmd + B)
- Player Settings

下载
游戏
Release: https://github.com/GameDevLog/GameDevLogTemplete/releases