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 | Action |
Tags | Singleplayer, Top down shooter |
More posts
- Diwali_Rifle Code Implementation😁38 days ago
- Sword Weapon Code Implementation44 days ago
- New Sword Weapon and Dash ability46 days ago
- Hit Effects and Mini Map53 days ago
- Player Movement Animations with Blend Tree60 days ago
- Add Precision Aim for Player and Update Guard Enemy with Laser Mechanics67 days ago
- Guard Enemy Implementation73 days ago
- Guard Enemy77 days ago
- Enemy Pool79 days ago
- Enemy Handling System81 days ago
Leave a comment
Log in with itch.io to leave a comment.