Guess The Number / 猜数字

游戏展示

Guess The Number

游戏开发

创建 2D 游戏

设置分辨率 1280x720

InputField

  • Hirearchy
    • Create
      • UI
        • InputField
  • Inspector
    • Rect Transform
      • Width: 700
      • Height: 80

Canvas

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

InputField > Text

  • Inspector
    • Text(Script)
      • fontSize: 60
    • Paragraph
      • Alignment: center

InputField > Placeholder

  • Inspector
    • Text(Script)
      • Text: Enter Your Guess
    • Paragraph
      • Alignment: center

Text

  • Hirearchy

    • Canvas
      • Create
        • Text
  • Inspector

    • Rect Transform
      • Pos X: 0
      • Pos Y: 218
      • Width: 700
      • Height: 80
    • Text(Script)
      • Text: Guess A Number Between 0 And 100
    • Paragraph
      • Alignment: center

Camera

  • Inspector
    • Camera
      • Background: Black

Button

  • Hirearchy

    • Canvas
      • Create
        • Text
  • Inspector

    • Text(Script)
      • Text: Guess

Button -> Text

  • Inspector
    • Rect Transform
      • Pos X: 0
      • Pos Y: -162
      • Width: 300
      • Height: 108

GuessTheNumberScript

  • Project
    • Create
      • Folder: Scripts
    • Scripts
      • Create
        • C# Script: GuessTheNumberScript
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

添加 GuessTheNumberScriptGameController

On Click

Button

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

导出游戏

  • File
    • Build Settings (Shift + Cmd + B)

Build Settings

  • Player Settings

下载

游戏

Release: https://github.com/GameDevLog/GameDevLogTemplete/releases

源码

GitHub: https://github.com/GameDevLog/GameDevLogTemplete

本文标题:Guess The Number / 猜数字

文章作者:iOSDevLog

发布时间:2019年12月05日 - 13:38:41

最后更新:2019年12月19日 - 15:40:59

原始链接:https://game.iosdevlog.com/2019/12/05/Guess-The-Number/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

iOSDevLog wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!