Search Unity

How to make player reappear on respawn point

Discussion in 'Scripting' started by Kruzaxxxxx, Oct 1, 2019.

  1. Kruzaxxxxx

    Kruzaxxxxx

    Joined:
    Sep 3, 2019
    Posts:
    2
    Hi im new to Unity and game development, and i wanna ask something about my 2D project
    my player keep disappearing on respawn point after falling to death zone,
    this is my code

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CheckPoints : MonoBehaviour
    6. {
    7.     public Transform checkpoint;
    8.     GameObject player;
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         player = GameObject.FindWithTag("Player");
    13.     }
    14.      
    15.     // Update is called once per frame
    16.     void OnTriggerEnter2D (Collider2D plyr)
    17.     {
    18.         if (plyr.gameObject.tag == "Player")
    19.         {
    20.             player.transform.position = checkpoint.position;
    21.        
    22.         }
    23.     }
    24. }
    Thank you in advance
     
  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    I asume this is on your dead zone? If you pause the editor after he disappears and look in the hierarchy, is your player still there? If so, where is he? Maybe its just a z order problem?
     
  3. Kruzaxxxxx

    Kruzaxxxxx

    Joined:
    Sep 3, 2019
    Posts:
    2
    yup my player still there, also in "Scene" but not in "Game"...
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You're going to have to be more clear regarding what the problem is, because it sounds like all you need to do is set the player's transform.position back to the respawn point position.
     
  5. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    So wherr in Scene is he, behind something else, invisible, falling down,...?