Question by
AmazingCore_Gaming · May 03, 2017 at 09:48 AM ·
c#2d2d gametop-down
Unity 5.4 2D Respawn Player at start point
In my game on unity i have a script for the player health to reach 0 then for something to happen, but in the tutorial im using it only explains how to set the object of inactive (i want him to respawm). I know how to reset the health back to the max health but how do I make the player teleport to an item with tag "Respawn". Here is my script bellow.
using UnityEngine; using System.Collections;
public class PlayerHealthManager : MonoBehaviour {
public int playerMaxHealth;
public int playerCurrentHealth;
// Use this for initialization
void Start () {
playerCurrentHealth = playerMaxHealth;
}
// Update is called once per frame
void Update () {
if(playerCurrentHealth <= 0)
{
//gameObject.SetActive(false);
playerCurrentHealth = playerMaxHealth;
//make play teleport to item with tag "Respawn"
}
}
public void HurtPlayer(int damageToGive)
{
playerCurrentHealth -= damageToGive;
}
public void SetMaxHealth()
{
playerCurrentHealth = playerMaxHealth;
}
}
Comment
Best Answer
Answer by memblock · May 03, 2017 at 10:00 AM
Something like
transform.position = GameObject.FindWithTag("ReSpawn").transform.position;
Or maybe you could just make up a position for the respawn point:
transform.position= new Vector3(0,0,0);
Option 1 worked perfefectly, thankyou very much :)