【发布时间】:2021-11-19 08:06:09
【问题描述】:
我在播放器上使用 NetworkIdentity、Network Transform (Script) 和 Network Transform child 作为组件。但我发现如果我检查“同步位置”,我的重生脚本就不再工作了
private IEnumerator Respawn()
{
yield return new WaitForSeconds(GameManager.instance.matchSettings.respawnTimer);
SetDefaults();
Transform spawnPoint = NetworkManager.singleton.GetStartPosition();
Debug.Log("Position avant : " + transform.position);
transform.position = spawnPoint.position;
transform.rotation = spawnPoint.rotation;
Debug.Log("position après : " + spawnPoint.position);
}
我的玩家停止移动,因为我在他死时停用了一些脚本(移动、射击脚本)
void Die()
{
isDead = true;
for (int i = 0; i < disableOnDeath.Length; i++)
{
disableOnDeath[i].enabled = false;
}
Collider col = GetComponent<Collider>();
if(col != null)
{
col.enabled = false;
}
StartCoroutine(Respawn());
}
要禁用的默认组件是:播放器的移动、他的摄像头、他的音频监听器和他的动作(暂时只拍摄)
void SetDefaults()
{
isDead = false;
currentHealth = MaxHealth;
for (int i = 0; i < disableOnDeath.Length; i++)
{
disableOnDeath[i].enabled = wasEnabledOnStart[i];
}
Collider col = GetComponent<Collider>();
if (col != null)
{
col.enabled = true;
}
}
唯一不起作用的是玩家在我的出生点重生。当玩家死亡时,他不能射击也不能移动。但它不会重生。
【问题讨论】: