This commit is contained in:
2026-05-30 09:16:35 +07:00
parent 2f87ce19a7
commit 1c0ee6efb7
4001 changed files with 3363438 additions and 1738 deletions

View File

@@ -0,0 +1,63 @@
using UnityEngine;
#if UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement;
#endif
namespace Invector.vCharacterController
{
public class vFindSpawnPoint : MonoBehaviour
{
public Transform spawnPoint;
public string spawnPointName;
public GameObject target;
public void AlighObjetToSpawnPoint(GameObject target, string spawnPointName)
{
this.target = target;
this.spawnPointName = spawnPointName;
// Debug.Log(spawnPointName+" "+gameObject.name);
#if UNITY_5_4_OR_NEWER
SceneManager.sceneLoaded += OnLevelFinishedLoading;
#endif
DontDestroyOnLoad(gameObject);
}
#if UNITY_5_4_OR_NEWER
void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
{
var spawnPoint = GameObject.Find(spawnPointName);
if (spawnPoint && target)
{
target.transform.position = spawnPoint.transform.position;
target.transform.rotation = spawnPoint.transform.rotation;
}
else
{
try
{
Destroy(gameObject);
}
catch { }
}
}
#else
public void OnLevelWasLoaded(int level)
{
var spawnPoint = GameObject.Find(spawnPointName);
if(spawnPoint && target)
{
target.transform.position = spawnPoint.transform.position;
target.transform.rotation = spawnPoint.transform.rotation;
}
else
{
try
{
Destroy(gameObject);
}
catch { }
}
}
#endif
}
}