72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
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 SetSpawn(Vector3 spawn)
|
|
{
|
|
spawnLocation = spawn;
|
|
setPoint = true;
|
|
}
|
|
|
|
private void OnLevelWasLoaded(int level)
|
|
{
|
|
print(spawnLocation);
|
|
if(level>1)
|
|
{
|
|
var temp = GameObject.Find("SpawnHere").transform;
|
|
DefaultPlayer.transform.position = temp.position;
|
|
//Instantiate(DefaultPlayer, temp.position, Quaternion.identity);
|
|
//DefaultPlayer.SetActive(true);
|
|
}
|
|
if(level==1)
|
|
{
|
|
if (!setPoint)
|
|
{
|
|
print("no default location set");
|
|
SpawnAtStart();
|
|
}
|
|
else
|
|
SpawnAtSetLocation();
|
|
|
|
}
|
|
}
|
|
|
|
private void SpawnAtSetLocation()
|
|
{
|
|
print("Spawn at set location");
|
|
//Instantiate(DefaultPlayer, spawnLocation, Quaternion.identity);
|
|
DefaultPlayer.transform.position = spawnLocation;
|
|
setPoint = false;
|
|
}
|
|
|
|
private void SpawnAtStart()
|
|
{
|
|
defaultPoint = GameObject.Find("DefaultPoint").transform;
|
|
DefaultPlayer.transform.position = defaultPoint.position;
|
|
//Instantiate(DefaultPlayer, defaultPoint.position, Quaternion.identity);
|
|
}
|
|
}
|