3月14日
制作玩家状态管理
创建一个空物体PlayerManager作为玩家状态的控制组件,并给他挂上同名脚本
public class PlayerManager : MonoBehaviour
{
//属性值
public int life = 3;
public int score = 0;
public bool isDead;
//引用
public GameObject born;
private static PlayerManager instance;//Ctrl+R+E快捷键生成单例
public static PlayerManager Instance { get => instance; set => instance = value; }
private void Awake()
{
Instance = this;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(life>0)
if (isDead)
{
Recover();
}
}
public void Recover()
{
if (life < 0)
{
}else
{
life--;
GameObject go = Instantiate(born, new Vector3(-2, -8, 0), Quaternion.identity);
go.GetComponent<Born>().createPlayer = true;
isDead = true;
}
}
}