Fix PlayerSpawnController bug that sometimes caused player to spawn in wrong location

This commit is contained in:
2022-08-18 10:48:18 -07:00
parent dd4a4b1eb6
commit 6c513aafc7
3 changed files with 15 additions and 4 deletions

View File

@@ -312,7 +312,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 455432347}
m_Enabled: 1
m_Enabled: 0
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
@@ -1383,7 +1383,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 7190262219221540737, guid: b273c0298305ae84e9a55d1de630edc0, type: 3}
propertyPath: m_LocalPosition.y
value: 24.68
value: 23
objectReference: {fileID: 0}
- target: {fileID: 7190262219221540737, guid: b273c0298305ae84e9a55d1de630edc0, type: 3}
propertyPath: m_LocalPosition.z

View File

@@ -1,3 +1,4 @@
using System.Linq;
using UnityEngine;
public class PlayerSpawnController : MonoBehaviour
@@ -9,7 +10,17 @@ public class PlayerSpawnController : MonoBehaviour
[SerializeField]
private GameObject _spawnLocation;
void Awake()
private void Awake()
{
var otherSpawnControllers = FindObjectsOfType<PlayerSpawnController>().Except(new[] { this });
if (otherSpawnControllers.Any())
Destroy(this);
else
DontDestroyOnLoad(this);
}
private void Start()
{
if (GameObject.FindGameObjectWithTag("Player") != null)
{

View File

@@ -27,7 +27,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7190262219221540742}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 26.18, y: 24.68, z: -18.753551}
m_LocalPosition: {x: 26.18, y: 23, z: -18.753551}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []