#I do something wrong when building my demo?

1 messages · Page 1 of 1 (latest)

tawdry iris
#

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!

#

Hope receiving your reply😭

wooden fiber
#

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...

tawdry iris
# wooden fiber Start with showing the scene setup, especially around the point the issue happen...

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.

wooden fiber
#

!code

desert fjordBOT
tawdry iris
# wooden fiber !code

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.

wooden fiber
#

You need to share the code correctly according to the guidelines...

tawdry iris
# wooden fiber 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);
        };
    }
}```
wooden fiber
#

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.