簡體   English   中英

與C#統一制作一個自定義計分器

[英]Make a custom score counter in unity with c#

我試圖統一創建一個自定義計分計數器,目前我正在使用以下代碼創建計分計數器。

`void OnGUI () {
         GUILayout.BeginArea ( new Rect( Screen.width/2-Screen.width / 8, 10, Screen.width / 4, Screen.height / 4 ) );
         GUILayout.Box ( score.ToString () );
         GUILayout.EndArea ();
     }`

我想要達到的目標就像一個數字時鍾類型計數器,因此會有背景圖片,然后背景中心的數字會隨着分數的增加而變化。 我還想實現一種輕彈,就像當分數增加時以筆記本型效果翻頁一樣。

編輯**我知道我可以使用guitexture並隨着得分的變化向其中添加不同的圖像,所以我能夠做到這一點,所以如果有人可以告訴我id如何添加動畫(如頁面)隨着得分的變化而變化,那將是完美的也。

任何幫助完成此過程的幫助

public GUITexture textureScore;
public Texture2D zero;
public Texture2D one;
public Texture2D two;
public Texture2D three;
public Texture2D four;
public Texture2D five;


void Update () {
    if(score == 0){
            textureScore.guiTexture.texture = zero;     
        }else if(score == 1){
            textureScore.guiTexture.texture = one;              
        }else if(score == 2){
            textureScore.guiTexture.texture = two;              
        }else if(score == 3){
            textureScore.guiTexture.texture = three;                
        }else if(score == 4){
            textureScore.guiTexture.texture = four;             
        }else if(score == 5){
            textureScore.guiTexture.texture = five;             
        }
}

並不完美,但是有效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM