第一步:场景新建Canvas和EmptyObject(这里命名outEmptyObject),Canvas下新建EmptyObject(这里命名innerEmptyObject),innerEmptyObject下创建按钮Button;
第二步:脚本附给outEmptyObject,Pause Button Text添加上一步创建的Button下的text,Ingame Menu添加ButtonContinueOrPause;
第三步:回到Button,添加On Click,第一个默认Runtime Only(根据需要选择),Object选择innerEmptyObject,Function选择ButtonContinueOrPause.OnClick;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ButtonContinueOrPause : MonoBehaviour{
public Text PauseButtonText;
public GameObject ingameMenu;
private bool count = true;
public void OnClick(){
if (count)
{
count = false;
PauseButtonText.text = "继续";
Time.timeScale = 0f;
}
else
{
count = true;
PauseButtonText.text = "暂停";
Time.timeScale = 1f;
}
}
}