So I am trying to make a 3D platformer for practice and I am confused on why the player spawn works on awake but then when it is triggered for respawning it doesn’t work.
Here is the Spawner Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour
{
Vector3 playerSpawn;
[SerializeField] Transform Player;
private void Awake()
{
Spawn(Player); //calls spawn
Debug.Log("Spawning Finished");
}
public void Spawn(Transform p)
{
playerSpawn = GameObject.FindGameObjectWithTag("Respawn").transform.position; //sets playerSpawn to Spawner position
Debug.Log(playerSpawn);
p.transform.position = playerSpawn; //Sets Player transform to playerSpawn
Debug.Log(p.transform.position);
Debug.Log("Spawn Triggered");
}
}
And here is my script for respawning:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KillBox : MonoBehaviour
{
public GameObject spawnerObject;
public Spawner spawnerScript;
[SerializeField] Transform Player;
Vector3 playerSpawn;
// Start is called before the first frame update
void Start()
{
spawnerScript = spawnerObject.GetComponent<Spawner>();
}
public void OnTriggerEnter(Collider other)
{
spawnerScript.Spawn(Player);
}
}