76 lines
1.7 KiB
C#
76 lines
1.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class SpawnManager : MonoBehaviour
|
|
{
|
|
public static SpawnManager Instance { get; private set; }
|
|
|
|
public GameObject DefaultPlayer;
|
|
|
|
private Transform _defaultPoint;
|
|
private Vector3 _spawnLocation;
|
|
private bool setPoint;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
else
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
SceneManager.sceneLoaded += SceneLoaded;
|
|
|
|
}
|
|
|
|
private void SetSpawn(Vector3 spawn)
|
|
{
|
|
_spawnLocation = spawn;
|
|
setPoint = true;
|
|
}
|
|
|
|
private void SceneLoaded(Scene arg0, LoadSceneMode arg1)
|
|
{
|
|
print(_spawnLocation);
|
|
if(arg0.buildIndex > 1)
|
|
{
|
|
var temp = GameObject.Find("SpawnHere").transform;
|
|
DefaultPlayer.transform.position = temp.position;
|
|
//Instantiate(DefaultPlayer, temp.position, Quaternion.identity);
|
|
}
|
|
if(arg0.buildIndex == 1)
|
|
{
|
|
if (!setPoint)
|
|
{
|
|
print("no default location set");
|
|
SpawnAtStart();
|
|
}
|
|
else
|
|
SpawnAtSetLocation();
|
|
|
|
}
|
|
}
|
|
|
|
private void SpawnAtSetLocation()
|
|
{
|
|
print("Spawn at set location");
|
|
DefaultPlayer.transform.position = _spawnLocation;
|
|
setPoint = false;
|
|
}
|
|
|
|
private void SpawnAtStart()
|
|
{
|
|
_defaultPoint = GameObject.Find("DefaultPoint").transform;
|
|
DefaultPlayer.transform.position = _defaultPoint.position;
|
|
}
|
|
}
|