代码在重启时无法播放? (机器人)

时间:2017-03-29 08:57:27

标签: c# android unity3d restart

所以我在android上做了一个无尽的跑步者(我知道原来的对吗?嗯......)一切都很好。但是当我死的时候按下重启按钮并输入以下代码:



SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);




游戏停止产生房间?知道为什么吗?这是我的发电室代码:



    void AddRoom(float farhtestRoomEndX) {
        //pick a random room from the array and instantiate it.
        int randomRoom = Random.Range(0, AllRooms.Length);
        GameObject room = (GameObject)Instantiate(AllRooms[randomRoom]);
 
        //Find the floor, and pos to instantiate(half of the screen) and add it to active rooms.
        float roomWidth = room.transform.FindChild("Floor").localScale.x;
        float roomCenter = farhtestRoomEndX + roomWidth * 0.5f;
        room.transform.position = new Vector3(roomCenter, 0, 0);
        ActiveRooms.Add(room);
    }
 
    void GenerateRoomIfRequired() {
        //Create a new list with rooms to be deleted, and make a bool to check if rooms need to be added
        List<GameObject> DeleteRooms = new List<GameObject>();
        bool AddRooms = true;
 
        //Save the playerPos, , calculate the point after when the room needs to be removed and calculate the starting pos for instantiating a new room
        float playerX = transform.position.x;
        float removeRoomX = playerX - screenWidthInPoints;
        float addRoomX = playerX + screenWidthInPoints;
 
        //store the point where the room ens, this is used to instantiate a new room aswell
        float farthestRoomEndX = 0;
 
       // use the floor to get the room width and calculate the roomStartX and roomEndX
        foreach (var room in ActiveRooms) {
            float roomWidth = room.transform.FindChild("Floor").localScale.x;
            float roomStartX = room.transform.position.x - (roomWidth * 0.5f);
            float roomEndX = roomStartX + roomWidth;
 
            //If there is a room that starts after addRoomX, delete it. or ends to the left of removeRoomX, delete it
            if (roomStartX > addRoomX)
                AddRooms = false;
 
            if (roomEndX < removeRoomX)
                DeleteRooms.Add(room);
 
            //the most right point of the level.
            farthestRoomEndX = Mathf.Max(farthestRoomEndX, roomEndX -0.01f);
        }
 
        //remove rooms that are marked as removal, and if addRooms is still true, add a new room
        foreach (var room in DeleteRooms) {
            ActiveRooms.Remove(room);
            Destroy(room);
        }
 
        if (AddRooms)
            AddRoom(farthestRoomEndX);
    }
&#13;
&#13;
&#13;

奇怪的部分是第一次运行得很好。 (上面的代码是从固定更新中调用的。)

0 个答案:

没有答案