Question by
erokex · Jul 19, 2019 at 09:08 PM ·
bugtransform.positionrespawnrespawningfpscontroller
fpscontroller doesnt respawn (maybe transform.position issue?)
Hey guys I´m making a respawn script following a tutorial. Everything works but when I click the "Respawn" button, my fpscontroller doesnt respawn at the spawnpoint but at his last position. https://streamable.com/99264
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityStandardAssets.Characters.FirstPerson;
public class RespawnSystem : MonoBehaviour
{
FirstPersonController freezePlayer;
MeleeSystem freezeAttacking;
MeshRenderer weapon;
public Transform respawnLocation;
public static bool playerIsDead = false;
public Button buttonRespawn;
public Button buttonMainMenu;
public Button buttonQuitGame;
void Start()
{
freezePlayer = GetComponent(typeof(FirstPersonController)) as FirstPersonController;
freezeAttacking = GameObject.Find("FirstPersonCharacter").GetComponent(typeof(MeleeSystem)) as MeleeSystem;
weapon = GameObject.Find("Schwert").GetComponent(typeof(MeshRenderer)) as MeshRenderer;
}
void Update()
{
if (playerIsDead == true)
{
freezePlayer.enabled = false;
freezeAttacking.enabled = false;
weapon.enabled = false;
buttonRespawn.gameObject.SetActive(true);
buttonMainMenu.gameObject.SetActive(true);
buttonQuitGame.gameObject.SetActive(true);
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
public void RespawnPlayer()
{
transform.position = respawnLocation.position;
transform.rotation = respawnLocation.rotation;
Debug.Log(transform.position);
gameObject.SendMessage("respawnStats");
freezePlayer.enabled = true;
freezeAttacking.enabled = true;
weapon.enabled = true;
buttonRespawn.gameObject.SetActive(false);
buttonMainMenu.gameObject.SetActive(false);
buttonQuitGame.gameObject.SetActive(false);
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
playerIsDead = false;
gameObject.SendMessage("HealthBar");
}
public void LoadMainMenu()
{
SceneManager.LoadScene(0);
}
public void QuitGame()
{
Application.Quit();
}
}
Comment