我正在使用Unity 2019.3.0a4。游戏对象在“场景”编辑器中可见,但在“游戏”屏幕中不可见。虽然它功能齐全,但我可以四处走动,并且仍然可以做我通常可以做的所有事情。
//This is in the script in the player, the gameobject that is invisible:
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Enemy")
{
GameObject gameCtrl = GameObject.Find("GameControl");
GameController gameController = gameCtrl.GetComponent<GameController>();
gameController.life--;
gameController.isDead = true;
player.SetActive(false);
}
}
//This is in another script in another object, so that it would work even when the player in inactive:
private void Update()
{
if (isDead == true)
{
respawnUI.SetActive(true);
}
if (isDead == true && Input.GetKeyDown(KeyCode.R))
{
respawnUI.SetActive(false);
isDead = false;
player.transform.position = spawnPoint.transform.position;
player.SetActive(true);
}
}
}
//Both scripts are correctly referencing the player gameobject.
没有错误消息。其他一切正常,玩家的游戏对象在游戏屏幕中只是不可见。