Question by
unity_EyP9NHLeVRC_LQ · Apr 22, 2021 at 09:08 PM ·
solution
My player wont go to the respawn point,When my health reach 0 tp to. But it wont tp my character
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LivManager : MonoBehaviour {
public int maxHealth;
public int currentHealth;
public float invincibilityLenght;
private float invincibilityCounter;
public Renderer PlayerRenderer;
private float flashCounter;
public float flashLength = 0.1f;
public Transform respawn;
public GameObject thePlayer;
public float healthBarLengh;
// Start is called before the first frame update
void Start()
{
healthBarLengh = Screen.width / 2;
currentHealth = maxHealth;
}
// Update is called once per frame
void Update()
{
if(invincibilityCounter > 0)
{
invincibilityCounter -= Time.deltaTime;
flashCounter -= Time.deltaTime;
if(flashCounter <= 0)
{
PlayerRenderer.enabled = !PlayerRenderer.enabled;
flashCounter = flashLength;
}
if(invincibilityCounter <= 0)
{
PlayerRenderer.enabled = true;
}
if(currentHealth <= 0)
{
KillPlayer();
}
}
}
//Livbar
void OnGUI() {
GUI.Box(new Rect(10, 40, healthBarLengh, 20), currentHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj) {
currentHealth += adj;
}
//respawn
public void KillPlayer()
{
currentHealth = maxHealth;
thePlayer.transform.position = respawn.position;
}
//skad spilleren
public void HurtPlayer(int damage)
{
if(invincibilityCounter <= 0)
{
currentHealth -= damage;
invincibilityCounter = invincibilityLenght;
PlayerRenderer.enabled = false;
flashCounter = flashLength;
}
}
//Heal spilleren
public void HealPlayer(int healAmount)
{
currentHealth += healAmount;
if(currentHealth > maxHealth)
{
currentHealth = maxHealth;
}
}
} ,using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LivManager : MonoBehaviour {
public int maxHealth;
public int currentHealth;
public float invincibilityLenght;
private float invincibilityCounter;
public Renderer PlayerRenderer;
private float flashCounter;
public float flashLength = 0.1f;
public Transform respawn;
public GameObject thePlayer;
public float healthBarLengh;
// Start is called before the first frame update
void Start()
{
healthBarLengh = Screen.width / 2;
currentHealth = maxHealth;
}
// Update is called once per frame
void Update()
{
if(invincibilityCounter > 0)
{
invincibilityCounter -= Time.deltaTime;
flashCounter -= Time.deltaTime;
if(flashCounter <= 0)
{
PlayerRenderer.enabled = !PlayerRenderer.enabled;
flashCounter = flashLength;
}
if(invincibilityCounter <= 0)
{
PlayerRenderer.enabled = true;
}
if(currentHealth <= 0)
{
KillPlayer();
}
}
}
//Livbar
void OnGUI() {
GUI.Box(new Rect(10, 40, healthBarLengh, 20), currentHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj) {
currentHealth += adj;
}
//respawn
public void KillPlayer()
{
currentHealth = maxHealth;
thePlayer.transform.position = respawn.position;
}
//skad spilleren
public void HurtPlayer(int damage)
{
if(invincibilityCounter <= 0)
{
currentHealth -= damage;
invincibilityCounter = invincibilityLenght;
PlayerRenderer.enabled = false;
flashCounter = flashLength;
}
}
//Heal spilleren
public void HealPlayer(int healAmount)
{
currentHealth += healAmount;
if(currentHealth > maxHealth)
{
currentHealth = maxHealth;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Unity rewrite sln file causing Assembly-CSharp error 1 Answer
How do I add scripts from a separate Unity project into my VS solution? 1 Answer
Why after importing Standard Assets my Visual Studio Solution has 3 projects ? 1 Answer
I have a problem with the lightning box terrain asset/script 0 Answers
Mario moves highground? 0 Answers