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 update
void Start()
{
scoreText = GameObject.Find("Canvas/score").GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
}
private void OnGUI()
{
scoreText.text = score.ToString();
}
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("触发");
if (!isAdd) score++;
isAdd = true;
}
}
把脚本拖拽到柱子里面