本文主要是介绍unity 2d 入门 飞翔小鸟 Cinemachine 记录分数(十二),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、创建文本
右键->create->ui->leagcy->text
2、设置字体
3、设置默认值和数字
4、当切换分辨率,分数不见问题
拖拽这里调整
调整到如下图
5、编写得分脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;public class Score : MonoBehaviour
{private static int score = 0;private Text scoreText;private bool isAdd=false;// Start is called before the first frame updatevoid Start(){scoreText = GameObject.Find("Canvas/score").GetComponent<Text>();}// Update is called once per framevoid Update(){}private void OnGUI(){scoreText.text = score.ToString();}private void OnTriggerEnter2D(Collider2D collision){Debug.Log("触发");if (!isAdd) score++;isAdd = true;}
}
把脚本拖拽到柱子里面
效果
这篇关于unity 2d 入门 飞翔小鸟 Cinemachine 记录分数(十二)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!