crkasce.blogg.se

Making 2d rpg games in unity
Making 2d rpg games in unity










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

  • Add a new Script component and call it simply Item.
  • Set Body Type to Kinematic inside the Rigidbody 2D component.
  • Try to fit the boundaries of the collider box into the item shape.
  • Click on the Edit Collider icon ( ) under the Box Collider 2D component.
  • In my case I’ve set Order in Layer to 3 since my platforms are on layer 2 and backgrounds on layers 4 and higher. This will ensure that all items are going to be visible. Here you have to keep in mind that the layer has to be in front of the background but behind the foreground ones. After that enter the number of the layer which collectibles are going to be rendered at.
  • Drag & drop the item sprite into the appropriate field inside the Sprite Renderer component panel.
  • They will be responsible for rendering graphics, animations as well as capturing physical collisions between the character and the collectible.
  • Add the Sprite Renderer, Box Collider 2D, Rigidbody 2D and Animator components in the Inspector panel.
  • Click on the newly created prefab object and hit Open Prefab button inside the Inspector panel.
  • In project Hierarchy add a new Empty Game Object and drag & drop it into your Assets folder.
  • #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.

    making 2d rpg games in unity

    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.

  • What did we get again? Labeling your collectibles!.
  • Adding pick-up “sparkles” to collectibles prefab.
  • Super Mario Bros by Nintendo Table of contents:










    Making 2d rpg games in unity