diamond for score, potion to add to inventory etc.) Register a collision between the character and sprite in order to trigger the event for adding an advantage dictated by collectible type (e.g.Our script should be able to handle three main operations to fulfill the following objectives: It may be a healing item that can be added to inventory for later use or simply score points that may be exchanged for other goods at a shop. In other words, once the character touches a clearly distinct sprite representing an item, the player gains some sort of “advantage”. Most mechanisms dealing with collectibles in 2D platformers fit within the simplistic nature of their gameplay. In a way it was the second part of the system since we were able to use the items but we couldn’t pick them up (unless of course we are talking about treasure chests in an RPG). However, back then I haven’t focused on logic for collecting them in the game world. I have already touch-based the implementation of a simple items system. Let’s now move on to writing a script that will be responsible for updating the state of our inventory and score. We have finished setting up the prefab item. We are going to use it to implement all logic handling the collection.
#Making 2d rpg games in unity code#
In fact the Object Oriented Programming (OOP) paradigm even encourages structuring your code around classes and objects! I’ll follow this principle in our Unity project.
It is only natural to have a template from which we may create many single coins, health potions, ammo and so on. The assumption here is that one collectible type may appear multiple times in the game. I’m going to start by creating a generic item prefab.