During my tests in Unity, everything worked fine—the player doesn't fall endlessly when transitioning between scenes, and there are no such issues when running the built exe file either. However, after I shared the packaged file with my friends, they reported that the player keeps falling in their case. I'm not sure why this is happening. Could it be that I missed some settings during the packaging process, causing the player's spawn point in the new scene to shift? I'd really appreciate any help on this!
#I do something wrong when building my demo?
1 messages · Page 1 of 1 (latest)
You'll need to share a lot more info than that to get any help...
Start with showing the scene setup, especially around the point the issue happens. Share code that is relevant, prefabs, gameobject inspectors, etc...
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class DoorTrigger : MonoBehaviour
{
[Header("目标场景配置")]
public string targetSceneName;
public string spawnPointName;
public PlayerMovement playerMovement;
[Header("调试设置")]
public bool debugLog = true;
void Update()
{
if (playerMovement == null)
{
GameObject player = GameObject.FindGameObjectWithTag("Player");
if (player != null)
{
playerMovement = player.GetComponent<PlayerMovement>();
}
}
}
private void OnTriggerEnter(Collider other)
{
if (debugLog) Debug.Log($"进入触发器的对象:{other.name}(标签:{other.tag})");
if (!other.CompareTag("Player")) return;
playerMovement.canMove = false;
GameObject player = other.gameObject;
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(targetSceneName);
asyncLoad.completed += (operation) =>
{
GameObject spawnPoint = GameObject.Find(spawnPointName);
if (spawnPoint == null)
{
Debug.LogError($"错误:目标场景「{targetSceneName}」中未找到名为「{spawnPointName}」的出生点对象!");
return;
}
playerMovement.canMove = true;
player.transform.position = spawnPoint.transform.position;
player.transform.rotation = spawnPoint.transform.rotation;
if (debugLog) Debug.Log($"玩家已跳转至场景「{targetSceneName}」的出生点「{spawnPointName}」(位置:{spawnPoint.transform.position})");
Debug.Log("other.position:" + other.transform.position);
Debug.Log("spawnPoint.position:" + spawnPoint.transform.position);
};
}
}This is the code that triggers the scene transition when the player is near the door. The coordinates printed in the last two lines of the debug information in the console are identical. The player settings are as shown in the image.
!code
Posting code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class DoorTrigger : MonoBehaviour
{
[Header("目标场景配置")]
public string targetSceneName;
public string spawnPointName;
public PlayerMovement playerMovement;
[Header("调试设置")]
public bool debugLog = true;
void Update()
{
if (playerMovement == null)
{
GameObject player = GameObject.FindGameObjectWithTag("Player");
if (player != null)
{
playerMovement = player.GetComponent<PlayerMovement>();
}
}
}
private void OnTriggerEnter(Collider other)
{
if (debugLog) Debug.Log($"进入触发器的对象:{other.name}(标签:{other.tag})");
if (!other.CompareTag("Player")) return;
playerMovement.canMove = false;
GameObject player = other.gameObject;
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(targetSceneName);
asyncLoad.completed += (operation) =>
{
GameObject spawnPoint = GameObject.Find(spawnPointName);
if (spawnPoint == null)
{
Debug.LogError($"错误:目标场景「{targetSceneName}」中未找到名为「{spawnPointName}」的出生点对象!");
return;
}
playerMovement.canMove = true;
player.transform.position = spawnPoint.transform.position;
player.transform.rotation = spawnPoint.transform.rotation;
if (debugLog) Debug.Log($"玩家已跳转至场景「{targetSceneName}」的出生点「{spawnPointName}」(位置:{spawnPoint.transform.position})");
Debug.Log("other.position:" + other.transform.position);
Debug.Log("spawnPoint.position:" + spawnPoint.transform.position);
};
}
}This is the code that triggers the scene transition when the player is near the door. The coordinates printed in the last two lines of the debug information in the console are identical.
You need to share the code correctly according to the guidelines...
using UnityEngine.SceneManagement;
using System.Collections;
public class DoorTrigger : MonoBehaviour
{
[Header("目标场景配置")]
public string targetSceneName;
public string spawnPointName;
public PlayerMovement playerMovement;
[Header("调试设置")]
public bool debugLog = true;
void Update()
{
if (playerMovement == null)
{
GameObject player = GameObject.FindGameObjectWithTag("Player");
if (player != null)
{
playerMovement = player.GetComponent<PlayerMovement>();
}
}
}
private void OnTriggerEnter(Collider other)
{
if (debugLog) Debug.Log($"进入触发器的对象:{other.name}(标签:{other.tag})");
if (!other.CompareTag("Player")) return;
playerMovement.canMove = false;
GameObject player = other.gameObject;
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(targetSceneName);
asyncLoad.completed += (operation) =>
{
GameObject spawnPoint = GameObject.Find(spawnPointName);
if (spawnPoint == null)
{
Debug.LogError($"错误:目标场景「{targetSceneName}」中未找到名为「{spawnPointName}」的出生点对象!");
return;
}
playerMovement.canMove = true;
player.transform.position = spawnPoint.transform.position;
player.transform.rotation = spawnPoint.transform.rotation;
if (debugLog) Debug.Log($"玩家已跳转至场景「{targetSceneName}」的出生点「{spawnPointName}」(位置:{spawnPoint.transform.position})");
Debug.Log("other.position:" + other.transform.position);
Debug.Log("spawnPoint.position:" + spawnPoint.transform.position);
};
}
}```
Ok, I don't see any issues in this script. It's not ideal that a script from a previous scene persists and does logic in the new scene, but I don't think that's related to the issue.