Diamond Pickup
Added pickup feature with diamond pickup.
Implementation Overview
This script defines an abstract Pickup
class for collectible items in Unity. It detects when the player collects the item. The Diamond
class extends Pickup
and implements specific behavior upon collection.
Class Structure
1. Pickup (Abstract Base Class)
Fields:
-
const string playerTagString
: Tag string to identify the player object (default:"Player"
).
Methods:
-
void OnTriggerEnter(Collider other)
-
Checks if the colliding object has the "Player" tag.
-
Calls
OnPickup()
when collected. -
Destroys the pickup object after collection.
void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag(playerTagString)) { OnPickup(); Destroy(gameObject); } }
-
-
protected abstract void OnPickup()
-
Abstract method to be implemented by subclasses to define unique behavior upon collection.
-
public abstract class Pickup : MonoBehaviour { const string playerTagString = "Player"; void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag(playerTagString)) { OnPickup(); Destroy(gameObject); } } protected abstract void OnPickup(); }
2. Diamond (Derived Class)
Inherits from: Pickup
Overrides:
-
protected override void OnPickup()
-
Logs a message to the Unity console.
-
Calls
MazeGenerator.instance.CreateDoors(DoorType.Exit);
to create exit doors. -
Placeholder for additional functionality.
protected override void OnPickup() { Debug.Log("Diamond Pickup!"); MazeGenerator.instance.CreateDoors(DoorType.Exit); }
-
public class Diamond : Pickup { protected override void OnPickup() { Debug.Log("Diamond Pickup!"); MazeGenerator.instance.CreateDoors(DoorType.Exit); } }
Summary
-
The
Pickup
class provides a template for collectible objects with player detection. -
The
Diamond
class implements specific functionality for its collection event. -
Other pickups can be created by extending
Pickup
and implementingOnPickup()
with unique behavior.
Maze Escape
Navigate the maze, grab the diamond, survive the hunt!
Status | Prototype |
Author | Goutamraj |
Genre | Survival |
Tags | Singleplayer, Top down shooter |
More posts
- Add Precision Aim for Player and Update Guard Enemy with Laser Mechanics4 days ago
- Guard Enemy Implementation10 days ago
- Guard Enemy14 days ago
- Enemy Pool16 days ago
- Enemy Handling System18 days ago
- CellsPool (ObjectPool for Maze Cells)20 days ago
- Game Loop21 days ago
- Entry and Exit path22 days ago
- Player State Machine25 days ago
Leave a comment
Log in with itch.io to leave a comment.