I’m trying to make a roguelike game for my school project. I tried to follow this tutorial: Basic 2D Dungeon Generation - YouTube This is my first time using Unity but I have a bit of experience with C#. My problem is that every time I play my scene, I get a “No cameras rendering” error on my game window. But sometimes, when I just keep clicking the play button, it works. What can I do to resolve this?
that means your camera isnt active. Idk why your camera isnt active, but its not.
if you have a Player, make sure his camera is turned on or add one to him
I think the issue is this bit of code
if (i == rooms.Length * .5f)
{
Vector3 playerPos = new Vector3(rooms_.xPos, rooms*.yPos, 0);*_
Instantiate(player, playerPos, Quaternion.identity);
}
As this checks that i is equivalent to half of the rooms being generated. On an even number this works fine, 10 / 2 = 5 so room 5 is where the player is placed. However, when done when there is an odd number of rooms this condition is never met because 5 / 2 = 2.5 and there is no room 2.5. Something like that. This means that approximately half the time your player is never instantiated.
I’m using this code now and haven’t seen any issues since
private bool playerPlaced = false;
if (i >= rooms.Length * .5f && !playerPlaced)
{
Vector3 playerPos = new Vector3(rooms_.xPos, rooms*.yPos, 0);
Instantiate(player, playerPos, Quaternion.identity);
playerPlaced = true;
}
You should also be able to round the rooms.Length * .5f and have it work as well though I haven’t tried this one. It might still be possible for two different values to be returned, one that rounds up and one that rounds down, which could cause issues still.
if (i == Mathf.RoundToInt(rooms.Length * .5f))
{
Vector3 playerPos = new Vector3(rooms.xPos, rooms.yPos, 0);
Instantiate(player, playerPos, Quaternion.identity);
}*
Always a good idea to keep in mind you should never use == when dealing with floating point values and should use >= or <= instead or round the value to the nearest integer. It’s not an uncommon mistake when writing code on the spot though._