I keep going completely off the rails with this camera controller, unable to navigate back to seeing any of the map, let alone something interesting.
Let’s do something about that:
So now Space will return the camera to its original position, and N will make us look at a random NPC? To do that, we’ll need to save (and be able to restore) the initial
camera settings:
We need a System.Random because we want integers, and UnityEngine.Random will only give us floats.
Demonstration
Hitting Space:
Hitting N:
Yes, I added in a few more of the common surface NPC types. But sometimes we’re not seeing the NPC that we’re centered on; what’s up with that?
Oops
If we switch to an NPC that’s underground, we don’t see it unless we’ve manually disappeared the map layers above it. That won’t do. We need to be more dynamic in updating
the Z-layer filter. We’ll split it out into a method we can call with an arbitrary Z, and keep track of that as well:
if(Input.GetKeyDown(KeyCode.N)){Vector3randomNpcCoords=map_manager.locateRandomNpc();mainCamera.lookAtNpc(randomNpcCoords);map_manager.UpdateZ(randomNpcCoords.z+1f);}}voidOnGUI(){GUI.Box(newRect(0,0,100,50),"# of cells\n"+map_manager.num_cells);GUI.Box(newRect(Screen.width-100,0,100,50),"# of blocks\n"+map_manager.num_blocks);GUI.Box(newRect(0,Screen.height-50,100,50),"Z top\n"+map_manager.zTop);StringBuilderbuilder=newStringBuilder();foreach(intgameRoundinmap_manager.activeGameRounds)builder.Append(gameRound).Append(" ");GUI.Box(newRect(Screen.width-100,Screen.height-50,100,50),"Game Round\n"+builder.ToString());}