简体   繁体   English

在 unity 2d 中加载新场景时出现问题

[英]problem when load a new scene in unity 2d

I have a problem, I'm making a 2d game in unity and i've create a scene that is load at the begining where my player is load, and then it sends it into the scene "salleA".我有一个问题,我正在统一制作一个 2d 游戏,我创建了一个场景,该场景在我的播放器加载开始时加载,然后将其发送到场景“salleA”。 I started by trying to lauch the game from this scene without adding a box collider for the walls of salleA, it worked.我开始尝试从这个场景启动游戏,但没有为 salleA 的墙壁添加盒式碰撞器,它成功了。 Then I added a box collider for the walls and it sends me to salleB, with a really strange display.然后我为墙壁添加了一个盒子碰撞器,它将我发送到 salleB,显示非常奇怪。 Please I'm a beginner I don't understand.请我是初学者,我不明白。 Here are the pictures:以下是图片:

salle A:销售A: 沙龙A

salle B: B厅: 销售B

and finally the strange display, when game is lauch but from the scene view:最后是奇怪的显示,当游戏启动但从场景视图: 奇怪的显示

I precise that the black squares are box collider trigger.我明确指出黑色方块是盒式碰撞机触发器。 The right one of salleA make you go to salle B and the left one of salleB make you go to salle A. salleA 的右边一个让你 go 到 salle B 而 salleB 的左边一个让你 go 到 salle A。

code of the first scene where the player is create:创建播放器的第一个场景的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class changeSalle : MonoBehaviour
{
    public Collider2D player;
    // Start is called before the first frame update
    void Start()
    {
        SceneManager.LoadScene("salleA");
        DontDestroyOnLoad(player);
    }

}

the collider of the player: (capsule)玩家的对撞机:(胶囊) 玩家对撞机

the collider of the salleA: (edge) salleA 的对撞机:(边缘) salleA 对撞机

After more searches, I think that the problem is more difficult.经过更多的搜索,我认为这个问题更难了。 I tried to put a camera in the sceneA and lauch the scene, it sends me to salleB with the message "no camera rendering", that is normal because the camera is a child of player that isn't destroy on load of each scene.我试图在 sceneA 中放置一个相机并启动该场景,它向 salleB 发送消息“无相机渲染”,这是正常的,因为相机是玩家的孩子,不会在每个场景的加载时被破坏。 So I tried to remove the door to Salle B, I lauched and it sends me to salleC, the scene that you can reach by the left black square.所以我试着移开通往 Salle B 的门,我笑了,它把我送到了 salleC,你可以通过左边的黑色方块到达那个场景。 Then I removed the door to salleC and I lauched.然后我移开通往 salleC 的门,然后大笑起来。 It lets me in the SalleA, but I only see yellow.它让我进入 SalleA,但我只看到黄色。 Picture:图片: 相机渲染 I think nothing else is important, if you need something else tell me in the comments.我认为其他都不重要,如果您需要其他内容,请在评论中告诉我。 Thanks, Ilou.谢谢,伊卢。

It now works, I tried so many things and I recreated the collider, I sized it to make it touch no other possible collider, like the sellers' collider, and it's good.它现在可以工作了,我尝试了很多东西并重新创建了对撞机,我调整了它的大小以使其不接触其他可能的对撞机,例如卖家的对撞机,这很好。 I think that unity doesn't like when you overlap colliders.我认为当你重叠对撞机时,团结不喜欢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM