【发布时间】:2017-11-10 02:44:26
【问题描述】:
我正在为我所在的大学班级制作一个非常短的 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);
}
}
【问题讨论】:
-
介意我问你的回放逻辑是如何工作的吗?由于它是无法按预期工作的部分,因此有助于找到解决方案。
-
@MaglethongSpirr 是的,因为 cmets 中没有足够的字空间,所以我肯定会将该脚本放在我原来的问题中。
-
在我看来你忘了打电话给
<player reference>.SetActive(true)来重新激活它。那可能吗?或者是PlayerController.gameOver = false对你有用吗?请注意,如果您尝试在自己的脚本中重新激活播放器,则在使用SetActive(false)停用后将不会调用 Unity 消息(例如Update()或OnTriggerEnter())
标签: c# unity3d gameobject replay