【Space Shoot Project】UI

UI主要控制显示分数,以及提醒游戏结束&是否继续游戏

Steps:

1. Create a new Empty GameObject

2. Add a GUIText component

3. Update the GUIText’s transform position to place it in the Screen

4. Update the GUIText,  text with “Score Text”

 两个概念:

Screen Space :主要是 基于pixels,比如现在的游戏分辨率为  600 *900

Viewport Space:   主要讲的是UI ,0-1 value      (0,0) at left bottom (1,1) at right up

使用pixel 可以微调界面文字的位置(use pixel offset to mini-adjust the place)

image

GameController 中声明分数更新相关函数:

    public void AddScore (int newScoreValue)
    {
        score += newScoreValue;
        UpdateScore ();
    }

    void UpdateScore ()
    {
        scoreText.text = "Score: " + score;
    }

在distroyByContact 中,使用单例模式,找到gameControllerObject 的instance,后面使用单例的函数 AddScore

    void Start ()
    {
        GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
        if (gameControllerObject != null)
        {
            gameController = gameControllerObject.GetComponent <GameController>();
        }
        if (gameController == null)
        {
            Debug.Log ("Cannot find 'GameController' script");
        }
    }

其中,引用的GameContollerObject 变量中声明为 private
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不负初心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值