Search Unity

2D respawn error

Discussion in 'Scripting' started by FraX_DK, Mar 14, 2019.

  1. FraX_DK

    FraX_DK

    Joined:
    Apr 26, 2018
    Posts:
    23
    Hey I've made this respawn script but its just dosent work... someone knows why?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Respawn : MonoBehaviour
    6. {
    7.  
    8.     [SerializeField] private Transform player;
    9.     [SerializeField] private Transform RespawnPoint;
    10.  
    11.  
    12.     void onTriggerEnter2D(Collider2D other)
    13.     {
    14.         player.transform.position = RespawnPoint.transform.position;
    15.     }
    16.    
    17. }
    18.  
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Did you set a value for RespawnPoint?
    Did you set a value for player?

    Are there colliders on both your player and whatever the respawn object is? Is one a trigger? Do you have a Rigidbody2D on one of them?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Everything @Brathnann said and also: make sure this script is NOT on the thing that gets destroyed (or any of its children, obviously).
     
  4. FraX_DK

    FraX_DK

    Joined:
    Apr 26, 2018
    Posts:
    23
    the player got a rigidbody2D, both got collider2D's, the death plate got is on "is trigger"
     
  5. FraX_DK

    FraX_DK

    Joined:
    Apr 26, 2018
    Posts:
    23
    but I just fall through the object thats supposed to kill the player when is trigger is on
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    onTriggerEnter2D needs to be caps

    OnTriggerEnter2D

    All unity's special methods must start with a capital letter
     
    Kurt-Dekker likes this.