From 667c9901b6509f167c0d10efd4c8ce24596903f7 Mon Sep 17 00:00:00 2001 From: Vova <3emaster@gmail.com> Date: Mon, 6 Mar 2023 08:24:03 +0200 Subject: [PATCH] change depricated method usage --- Assets/Scripts/SpawnManager.cs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Assets/Scripts/SpawnManager.cs b/Assets/Scripts/SpawnManager.cs index a162b55d..b50f5b5a 100644 --- a/Assets/Scripts/SpawnManager.cs +++ b/Assets/Scripts/SpawnManager.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.SceneManagement; public class SpawnManager : MonoBehaviour { @@ -9,8 +10,8 @@ public class SpawnManager : MonoBehaviour public GameObject DefaultPlayer; - private Transform defaultPoint; - private Vector3 spawnLocation; + private Transform _defaultPoint; + private Vector3 _spawnLocation; private bool setPoint; private void Awake() @@ -22,26 +23,31 @@ public class SpawnManager : MonoBehaviour } else Destroy(gameObject); + + } + + private void Start() + { + SceneManager.sceneLoaded += SceneLoaded; } private void SetSpawn(Vector3 spawn) { - spawnLocation = spawn; + _spawnLocation = spawn; setPoint = true; } - private void OnLevelWasLoaded(int level) + private void SceneLoaded(Scene arg0, LoadSceneMode arg1) { - print(spawnLocation); - if(level>1) + print(_spawnLocation); + if(arg0.buildIndex > 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(arg0.buildIndex == 1) { if (!setPoint) { @@ -57,15 +63,13 @@ public class SpawnManager : MonoBehaviour private void SpawnAtSetLocation() { print("Spawn at set location"); - //Instantiate(DefaultPlayer, spawnLocation, Quaternion.identity); - DefaultPlayer.transform.position = spawnLocation; + 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); + _defaultPoint = GameObject.Find("DefaultPoint").transform; + DefaultPlayer.transform.position = _defaultPoint.position; } }