Unity手擼2048小遊戲——背景文字控制

來源:互聯網
上載者:User

標籤:div   str   mono   raycast   color   ext   ssm   情境   通道   

今天繼續昨天的計劃吧

1、建立項目、情境命名啥的都不說了吧。

2、直接開始建立一個Image,順便把Image改名成Chessman

3、選中Image建立一個Text對象,調整下大小位置。這樣就算完成了一格了吧。

4、開始擼代碼,建立代碼命名Chessman, 並且將代碼放到Chessman下面。代碼如下:

using UnityEngine;using System.Collections;using UnityEngine.UI;public class ChessMan : MonoBehaviour {    private Image imageObj;    private Text textObj;    void Start () {        imageObj = GetComponent<Image> ();        imageObj.raycastTarget = false;                    textObj = GetComponentInChildren<Text> ();        textObj.raycastTarget = false;    }    //改變背景圖片顏色    public void fn_ChangeBg(Color _colorValue){        imageObj.color = _colorValue;    }    //改變文本文字,和對應的顏色    public void fn_ChangeText(string _textValue,Color _colorValue){        textObj.text = _textValue;        textObj.color = _colorValue;    }}

start()有:imageObj.raycastTarget = false;

     textObj.raycastTarget = false;

這是為了不接受射線,節約資源。這是前輩告訴我的,這樣可以節約資源(突然覺得拿不準的,都這麼說,好像是一個甩鍋的好借口)。

注意,當值為0時候,不管RGB的值時多少,A通道一定得設定為透明(00)

 

Unity手擼2048小遊戲——背景文字控制

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.