-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayerSpawner.cs
More file actions
28 lines (25 loc) · 824 Bytes
/
Copy pathPlayerSpawner.cs
File metadata and controls
28 lines (25 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SceneManagement;
public class PlayerSpawner : MonoBehaviour
{
void Start()
{
GameObject player = GameObject.FindWithTag("Player");
GameObject spawnPoint = GameObject.FindWithTag("SpawnPoint");
if (player != null && spawnPoint != null)
{
player.transform.position = spawnPoint.transform.position;
player.transform.rotation = spawnPoint.transform.rotation;
NavMeshAgent agent = player.GetComponent<NavMeshAgent>();
if (agent != null)
{
agent.Warp(spawnPoint.transform.position);
}
}
else
{
Debug.LogError("Player or SpawnPoint not found in the scene!");
}
}
}