-
-
Notifications
You must be signed in to change notification settings - Fork 96
Home
- The ghosts are running into the wall instead of turning
- The pellets are not disappearing when eaten
- How do I add scoring and lives?
- How do I install the '2D Tilemap Extras' package?
If the ghosts are not turning, this implies a problem with the node system since the ghosts only change direction when touching a node. First, make sure you don't have any missing nodes on any of the corners. Double check your Node prefab has a collider component with the Is Trigger
property checked on.
One of the easiest ways to cause this problem is by turning off the "Nodes" game object entirely instead of disabling only the Tilemap Renderer
component. The tilemap is only used as a visual debugging aid for the nodes, so we disable it for the actual game. However, if you disable the entire game object, this also disables the Node
scripts from running which is needed for the ghosts to move properly.
This problem is usually caused if you have assigned a sprite to the pellet tile asset(s). We assign the sprite to the SpriteRenderer
component on the pellet prefabs but not to the pellet tiles themselves. The prefabs are assigned to the tiles, and a copy of that object is spawned for each pellet tile on the map. Once these objects are spawned, they handle rendering the pellet and our scripts will disable the object once eaten. The script is unable to update the tilemap so if we assign a sprite to the tile asset, then it will show up permanently on the board.
I did not cover this in my tutorial video because the video was already so long, but I did include the implementation for scoring and lives in the full project source code: https://github.com/zigurous/unity-pacman-tutorial. Most of the code for this is handled in the GameManager.cs
script, if you want to take a look at how I handled it.
Documentation: https://docs.unity3d.com/Packages/[email protected]/manual/index.html
Editor method:
- Navigate to the menu
Edit > Project Settings
, then select thePackage Manager
settings. - Check on the box called
Enable Pre-release Packages
. - Navigate to the package manager from the menu
Window > Package Manager
. - Change the dropdown to
Packages: Unity Registry
. - Find the package called '2D Tilemap Extras' and click the
Install
button
Manual method:
- Open the file
Packages/manifest.json
in a text/code editor - Add a new entry
"com.unity.2d.tilemap.extras": "2.2.0",
alongside the other packages - The package should be automatically installed the next time you open the Unity editor