首先,创建一个text的ui组件,在其中写上你需要的文字。
接着对大小颜色等等进行调整:
?制作好之后,接着禁用该组件:
?接着完成就是通过条件代码激活该UI组件。
在玩家的代码中编写脚本如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class player_move : MonoBehaviour
{
public int score = 0;
public Text ScoreText;
public GameObject winText;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Rigidbody rd = GetComponent<Rigidbody>();
rd.AddForce(new Vector3(h, 0, v) * 13);
}
private void OnTriggerEnter(Collider other)
{
if (other .tag == "food")
{
Destroy(other .gameObject);
score++;
ScoreText.text = "分数:" + score;
if(score ==13)
{
winText.SetActive(true);
}
}
}
}
|