Question by
Extranomy · Feb 09, 2016 at 02:28 PM ·
playercolliderscollision detectionrespawncollisions
Player respawn after collision
I want my player to re-spawn after he hits certain game object. For example, water. Now player respawn only if I set player health(PlayerLive) to 0 or less in the Inspector. Actually, I'm not sure how to use OnCollisionEnter correctly. I attached this script to player:
using UnityEngine;
using System.Collections;
public class Respawn : MonoBehaviour {
public Transform SpawnPoint;
public int PlayerLife;
bool respawn = false;
void OnCollisionEnter(Collision col){
if (col.gameObject.name == "Water") {
PlayerLife = 0;
}
}
void Update () {
if (PlayerLife <= 0) {
respawn = true;
}
else {
respawn = false;
}
if (respawn) {
transform.position = SpawnPoint.position;
PlayerLife = 100;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Colliders for tunnels 0 Answers
Why is the Player Transform only changing correctly the first time? 1 Answer
rigidbody not moving 1 Answer
How i can fix a player controller bug? 0 Answers
Respawn fix 1 Answer