Baethor Baethor - 11 months ago 63
C# Question

Player Respawn and Death when falling

I'm going through the worse struggle right now. I'm trying to create a game with pitfalls that if the players fall through, they respawn and the game counts their death. I'm completely at wit's end and don't know where to even start with this. The game is 3D

using UnityEngine;
using System.Collections;

public class Respawn : MonoBehaviour {
public Transform spawnPoint;
public float minHeightForDeath;
public GameObject player;

void Start () {

// Update is called once per frame
void Update () {
if (player.transform.position.y < minHeightForDeath) {
player.transform.position = spawnPoint;

Answer Source

Use a collider on a plane/cube/whatever works for you, and set it to be a trigger. So when they pass through the trigger collider, it can record them and do what you want with it.

Use the OnTriggerEnter method script

void OnTriggerEnter(Collider other) 
    other.transform.position = spawnPoint.position;