Question by
Thambark92 · Mar 19, 2020 at 05:10 PM ·
respawnrespawningrespawner
ThePlayer should respawn at his start position after his health drops down to 0. However it doesn't work properly. Can somebody tell me what went wrong and how to fix it please?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class HealthManager : MonoBehaviour { public int maxHealth; public int currentHealth;
public PlayerController thePlayer;
private bool isRespawning;
public Vector3 respawnPoint;
public float RespawnLength;
// Start is called before the first frame update
void Start()
{
respawnPoint = thePlayer.transform.position;
currentHealth = maxHealth;
//thePlayer = FindObjectOfType<PlayerController>();
}
// Update is called once per frame
void Update()
{
}
public void Respawn()
{
thePlayer.gameObject.SetActive(true);
thePlayer.transform.position = respawnPoint;
currentHealth = maxHealth;
}
public void HealPlayer(int healAmount)
{
currentHealth += healAmount;
if (currentHealth > maxHealth)
{
currentHealth = maxHealth;
}
}
public void HurtPlayer(int damage, Vector3 direction)
{
currentHealth -= damage;
if (currentHealth <= 0)
{
GameObject player = GameObject.Find("Player");
CharacterController charController = player.GetComponent<CharacterController>();
Respawn();
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Respawn doesn't work ? 0 Answers
respawning with triggers in unity,How do i make only my player respawn? 0 Answers
Respawn System Not Working 1 Answer
Ragdoll death respawn help 0 Answers