I wrote some code so when the player falls off a platform and collides with a trigger collider called Respawn Trigger, the player's transform position is set to an empty gameObject called Respawn Point. Everything seems to work well except I get the following error each time I collide with the trigger and respawn:
UnassignedReferenceException: The variable player of PlayerRespawn has not been assigned.You probably need to assign the player variable of the PlayerRespawn script in the inspector. PlayerRespawn.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/PlayerRespawn.cs:9)
This is my script I put on my Respawn Trigger gameObject:
using UnityEngine; public class PlayerRespawn : MonoBehaviour { [SerializeField] private Transform player; [SerializeField] private Transform respawnPoint; void OnTriggerEnter2D(Collider2D other) { player.transform.position = respawnPoint.localPosition; } }