我正在为我所在的大学班级制作一个非常简短的 C# Unity 游戏,我已经为一个陷阱创建了一个脚本,该脚本在接触时停用我的玩家,其中还包括一个重播按钮。除了我重播时,播放器保持非活动状态,否则一切都有效。如何修改脚本以使播放器在重播时重新激活?另外,我参加的这个班是初学者班,我不是很擅长这个。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Trap : MonoBehaviour
{
public GameObject playerExplosion;
public GameObject gameOverUI;
void OnTriggerEnter (Collider other)
{
if (other.tag == "Player")
{
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
}
other.gameObject.SetActive(false);
gameObject.SetActive(false);
gameOverUI.SetActive(true);
PlayerController.gameOver = false;
}
}
编辑:这也是重播脚本。它适用于健康条系统。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ReplayGame : MonoBehaviour
{
public Transform player;
public Image uiBar;
public GameObject GameOverUI;
public static Vector3 startPosition;
private float fillAmount;
void Start()
{
startPosition = player.position;
fillAmount = uiBar.fillAmount;
GameOverUI.SetActive(false);
}
public void Click ()
{
PlayerController.gameOver = false;
player.position = startPosition;
uiBar.fillAmount = fillAmount;
GameOverUI.SetActive(false);
}
}
您必须重新激活您的播放器,或者您必须实例化一个新玩家。
public void Replay ()
{
//ReActivate
myPlayer.gameObject.SetActive(true);
//or Instnatiate a new
Instantiate(myPlayer);
}