Hey everyone! Hope you enjoyed the tutorial. Here's the link to the FREE Icon PACK: www.blackthornprod.com/epic-icon-pack And again, thanks to Data Camp for helping us out financially by sponsoring this video. Unlock new career opportunities and become data fluent today! Use the link bit.ly/BlackthornprodDCJan22 and check out the first chapter of any DataCamp course for FREE!
Probably worth noting that relying on string recipes and order of two independent list inside of the editor will become unmanageable really quickly for any meaningful quantity of recipes. Like someone mentioned, using scriptable objects, for example, could help make actual items and recipes much nicer and you could have some inline editors to drag and drop items to recipe slots. So while it works as a starting point for anyone wanting to build a system like this, as is, it is using some bad practices that can easily become tough to manage, especially if working with a team. I realise this is probably just to be able to scope down the tutorial to a bite-size chunk, but it would be advisable for anyone actually building something similar to spend some time on the recipe and recipe slot logic on any system aiming for production use (or even if you have a separate person or a team working on managing the content for your game). In solo dev, you can get away with more of these types of shortcuts, but you will probably still end up hating yourself at some point.
Awesome tutorial, but I think this can be improved a lot by using scriptable objects. Each item can be a SO as well as each recipe result. On the recipe SO you can have a recipe materials array of 4 items SO. This removes the need for writing down the material in a confusing string and you are keeping a reference to an actual asset making it much more organized. The in the crafting manager you could have a list of all the recipe results and search for the one that matches the current materials order by a simple comparison. Of course the items on the canvas would also need a script that holds a reference to their correspondent item SO
The only problem with the "CraftingManager" implementation, is that if you drag an item to the corner of the screen outside of a slot, it will drop the item to a slot because one of them is still the closest. The solution for it would be to add a variable for the minimum distance from the slot. Cheers
I mean, yeah, this works, but it's not neither the easiest nor optimized crafting system u gonna find. I guess it's good enough for a beginner solo dev that just wants to make a 4 item crafting system with a couple of recipies, because if scaled it will be a pain in the ass. I think i saw a couple of comments point this out, but using Scriptable Objects would be so much easier, for items and for recipies. I personally like the tutorials that are the base of a system were u can build over, not the air-tight ones where you make a completely closed system for people to replicate and deal with, just because everyone games are different so people might wanna change things and poke around. Either way, great video!
Great tutorial, I will definitely be using it in the future! But I think it can be improved by separating the items in the string receipe with some unique character, like ";" or "#". The reason for this is that currently, if I understand the code, recipes like "gearbox fire arm null" and "gear box firearm null" can't exist at the same time. I understand that it's not going to be a frequent problem, but I think the code shouldn't contain unexpected behavior for some weird cases if it can be avoided that easily.
Perfect tutorial. I tried drag and drop with the code monkey tut but it was so unnecessarily complex but this is so.simple and quick. Thank you so much Noa for this it's such. A helpful tutorial
Love the tutorial but a quick question, i have it to where a crafting menu opens and closes when pressing e on an object, however even while the slots are inactive the code still reads them as still there and will just go straight into the inactive slot, is there a way to prevent this and make the object go to the nearest slot that is shown on screen?
Crafting in my view is one of those often neglected mechanics that don't get many up to date tutorials on them, weirdly I've found this to be true for proper hitscan shooting as well and looking at how to do bullet tracers, very glad he made this.
Blackthornprod makes me feel like I live in a simulation 😂 every time I think about trying to make something, a week later he makes a video on how to do it
The way you coded the drag'n'drop system has a little issue: if you pick up the item but don't drag it onto one of the slots you are gonna expect the item to just go away but instead it is still going to choose the closest one and put the selected item in that slot. The way you should code is you should check if the distance between the selected item and one of the slots has a value equal to or smaller than a value that is predetermined, ideally set in inspector.
@@BenL-wh4pt Sure, there you go :) public float slotSelectionDistance; //At the top of the script with the other variables //Inside Update() if (Input.GetMouseButtonUp(0)) { if (currentItem != null) { customCursor.gameObject.SetActive(false); Slot selectedSlot = null; foreach (Slot slot in craftingSlots) { float dist = Vector2.Distance(Input.mousePosition, slot.transform.position); if (dist < slotSelectionDistance) { selectedSlot = slot; break; } } if (selectedSlot != null) { selectedSlot.gameObject.SetActive(true); selectedSlot.GetComponent().sprite = currentItem.GetComponent().sprite; selectedSlot.item = currentItem; currentItem = null; } } } If the code has any typos lemme know and I'll edit it :)
Can anyone pls tell that what all components are there in result slot and what you have written in index and item in slot script of result slot as my project is not working and also can anyone tell what have a done wrong just the result par is not working except that every thing is working pretty good plss someone help:(.
The also an idea about next tutorial could be about, I was thinking about weapon system where you are able to improve your weapon increase the damage of bullets or something like also I had in my mind tutorial about sword attack system like Idoz made in his game called archvale or even explain how to make a shop or quest systems.
Thanks for the video. I was really needing it. But currently I am facing a problem which is that how to collect the crafted item into the inventory. If someone know it, could you please give me suggestion? Thanks
lil bro is using strings AND looping through strings AND relying on same index to find the result on a different list NAAAAAAH AINTNOWAY youtube never disappoints with the goofy ah codes
In my opinion, the worst thing about this tutorial, or the overall approach to organising a crafting system this way, is using strings to store the recipes. Not only is it susceptible to spelling errors but also the very assumption that the player would drag and drop the items in the order described in the recipe is naïve because the string-building process is dependent on the order of the resources in the slots instead of what they actually are. Wouldn't it make much more sense to check the type and the quantity of the resources in the slots and then loop through all the existing recipes and check if the types and quantities of the resources match any recipe? Not to mention that all the logic runs in the Update methods where, to make things worse, you're using GetComponent methods. I would've added a Craft button or something that would call a method that gets all the resources in the slots, adds them to a class or a struct, passes it to another method that determines if anything can be crafted from the received resources and if so returns the crafted item.
I might investigate the code myself as well and see what's out there that's up to date, I think you do have a point about his use of strings and GetComponent. I realise strings are generally frowned upon when it comes to code efficiency because of the searches you have to do but with GetComponent code it can be done efficiently if it's setup the right way. Seems like it might be a good idea for BlackThorn to do an update video on this just to issue some corrections, if not, then people can post corrections in the comments page.
Can anyone of you please Guide That How do I complete my project very quickly. For example I was working for 1years in Game Development And Made a Ludo(Dummy)Game And Now working on a Project Of Chess Game for Last 7 months of Time with 4hrs a day But I have Done A little Of work Till Now But When I was Making I taught that it this or this work is so simple Just take up only a few minutes But It take 3 -6 Days but even I left something Out Can Any one of You Have the solution of this If yes Then please suggest me Because There are Better experience Game developer Than me
Hey, if you're looking to just make a general teleporting mechanic, it's actually quite straightforward, do a collision check on whatever your 'portal' gameobject is as your player is running through, then use something like transform.position = portal.transform.position to instantly move your player there once the player collides with the portal gameobject. You can also use this method if you're wanting to teleport a player with the mouse, just adapt the code to a raycast hit position. The way I would do it is attach a script to the portal itself and keep track of the connected portal you want the player to go to that way.
I clicked on this to see how you'd handle recipes but this method isn't great. It way too strict. the order will need to match. So you could do woodwoodstone but not woodstonewood etc. You also can't reorganize your recipes easily due to 2 lists that must match the order in the inspector. or let alone change the name of an ingredient.
Normally I like your content, but this recipe system just gave me cancer. Working with strings when not necessary is something everybody should avoid at all costs. Please next time look up beforehand how other devs handle your topic. Giving items the recipe in Form of an array of other items, or make a recipe containing the item to create and an array of items needed would be two way better options.
doesnt work at all nothing u did works at all, show the whole SCREEEEEENNNN AND SHOW EVERYTHINGGG YOU DOOOOOOOOOOOO WHY SKIP STEEEEEPPSSSSS AND ZOOOOM IN ON EVERYTHINGGGGG
I made a bit of a difference so you get the new item ... and the dragging does things better any questions ask Crafting manager : using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CraftingMan : MonoBehaviour { private Item currnetitem; public Image cursorCus; public Slots[] craftingslots; public GameObject[] result; public List itemlist; public string[] recipe; public Item[] repiperesult; public Slots resultslot; bool isitin = false; private void Update() { if (Input.GetMouseButtonUp(0)) { if (currnetitem != null) { if (!isitin) { currnetitem = null; cursorCus.gameObject.SetActive(false); return; } if (isitin) {
Hey everyone! Hope you enjoyed the tutorial. Here's the link to the FREE Icon PACK: www.blackthornprod.com/epic-icon-pack
And again, thanks to Data Camp for helping us out financially by sponsoring this video.
Unlock new career opportunities and become data fluent today! Use the link bit.ly/BlackthornprodDCJan22 and check out the first chapter of any DataCamp course for FREE!
Any way for us to access the source files?
Hey I submitted my email but can't download the pack. Please help
Probably worth noting that relying on string recipes and order of two independent list inside of the editor will become unmanageable really quickly for any meaningful quantity of recipes. Like someone mentioned, using scriptable objects, for example, could help make actual items and recipes much nicer and you could have some inline editors to drag and drop items to recipe slots. So while it works as a starting point for anyone wanting to build a system like this, as is, it is using some bad practices that can easily become tough to manage, especially if working with a team.
I realise this is probably just to be able to scope down the tutorial to a bite-size chunk, but it would be advisable for anyone actually building something similar to spend some time on the recipe and recipe slot logic on any system aiming for production use (or even if you have a separate person or a team working on managing the content for your game). In solo dev, you can get away with more of these types of shortcuts, but you will probably still end up hating yourself at some point.
i think this could be a cool twist if done right for a rouge like game EG Magicite and Rouge lands
Awesome tutorial, but I think this can be improved a lot by using scriptable objects. Each item can be a SO as well as each recipe result. On the recipe SO you can have a recipe materials array of 4 items SO. This removes the need for writing down the material in a confusing string and you are keeping a reference to an actual asset making it much more organized. The in the crafting manager you could have a list of all the recipe results and search for the one that matches the current materials order by a simple comparison. Of course the items on the canvas would also need a script that holds a reference to their correspondent item SO
I have to admit, I will come back to this video more than once! 😂 This is such a great topic and you explained it so well. Great job 👏
I love these specific tutorials, it really helps learning how to use the unity features to achieve different out comes, thank you!
The only problem with the "CraftingManager" implementation, is that if you drag an item to the corner of the screen outside of a slot, it will drop the item to a slot because one of them is still the closest.
The solution for it would be to add a variable for the minimum distance from the slot.
Cheers
I mean, yeah, this works, but it's not neither the easiest nor optimized crafting system u gonna find. I guess it's good enough for a beginner solo dev that just wants to make a 4 item crafting system with a couple of recipies, because if scaled it will be a pain in the ass. I think i saw a couple of comments point this out, but using Scriptable Objects would be so much easier, for items and for recipies. I personally like the tutorials that are the base of a system were u can build over, not the air-tight ones where you make a completely closed system for people to replicate and deal with, just because everyone games are different so people might wanna change things and poke around. Either way, great video!
Great tutorial, I will definitely be using it in the future!
But I think it can be improved by separating the items in the string receipe with some unique character, like ";" or "#".
The reason for this is that currently, if I understand the code, recipes like "gearbox fire arm null" and "gear box firearm null" can't exist at the same time.
I understand that it's not going to be a frequent problem, but I think the code shouldn't contain unexpected behavior for some weird cases if it can be avoided that easily.
This is really great! I'm planning to use something similar for crafting items & spells. Thank you & cheers!
Is there a way to download the source code? Hard to wrap the head around the code without seeing it. Thanks for a create video!
Perfect tutorial. I tried drag and drop with the code monkey tut but it was so unnecessarily complex but this is so.simple and quick. Thank you so much Noa for this it's such. A helpful tutorial
Love the tutorial but a quick question, i have it to where a crafting menu opens and closes when pressing e on an object, however even while the slots are inactive the code still reads them as still there and will just go straight into the inactive slot, is there a way to prevent this and make the object go to the nearest slot that is shown on screen?
you guys rock! one of the reasons i start programming, you and brackeys! greta job thanks a lot, keep it up!
I was waiting for a video like this!!
Amazing tutorial
Crafting in my view is one of those often neglected mechanics that don't get many up to date tutorials on them, weirdly I've found this to be true for proper hitscan shooting as well and looking at how to do bullet tracers, very glad he made this.
@@lethn2929 i agree
This is unrelated, but I think a stealth game in you're specific style would be really fun to play.
THIS MECHANIC IS PERFECT FOR MY GAME YOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!!!
hello im a complete beginner i am having trouble understanding what you mean by dry(?) images i know object but why does it glow blue?
Sunday HYPE!
Loved the approach you have took here.
I might've gone with something wayy more complex if I was making it myself
Blackthornprod makes me feel like I live in a simulation 😂 every time I think about trying to make something, a week later he makes a video on how to do it
You are not suposed to know that
Love your tutorials, keep up with them!
great tutorial, i agree with the comments about scriptable objects too. I will use elements of this tutorial to do a 2D cooking game. Thanks again BTP
The way you coded the drag'n'drop system has a little issue: if you pick up the item but don't drag it onto one of the slots you are gonna expect the item to just go away but instead it is still going to choose the closest one and put the selected item in that slot. The way you should code is you should check if the distance between the selected item and one of the slots has a value equal to or smaller than a value that is predetermined, ideally set in inspector.
can you write down the code there ? I am kinda bad at it ^^' . If not , i ll try this out
@@BenL-wh4pt Sure, there you go :)
public float slotSelectionDistance; //At the top of the script with the other variables
//Inside Update()
if (Input.GetMouseButtonUp(0))
{
if (currentItem != null)
{
customCursor.gameObject.SetActive(false);
Slot selectedSlot = null;
foreach (Slot slot in craftingSlots)
{
float dist = Vector2.Distance(Input.mousePosition, slot.transform.position);
if (dist < slotSelectionDistance)
{
selectedSlot = slot;
break;
}
}
if (selectedSlot != null)
{
selectedSlot.gameObject.SetActive(true);
selectedSlot.GetComponent().sprite = currentItem.GetComponent().sprite;
selectedSlot.item = currentItem;
currentItem = null;
}
}
}
If the code has any typos lemme know and I'll edit it :)
@@utkugokalp3179 what a legend you are , thx a lot , ill let you know if it work well ^^
@@BenL-wh4pt No problem :)
@@utkugokalp3179 hi i tested it and it doesnt work correctly what do we have to set for
slotSelectionDistance
Can anyone pls tell that what all components are there in result slot and what you have written in index and item in slot script of result slot as my project is not working and also can anyone tell what have a done wrong just the result par is not working except that every thing is working pretty good plss someone help:(.
Awesome tutorial ;) Definitely gonna use this for my upcoming R.P.G! Thanks again for this :)
Thank you so much Noah for you content which is extremely useful for me, thank you so much for your tutorials !
will you also make the other polls? eg Card game
We will :)!
@@Blackthornprod Yeahh thanks man! :')
exactly what i needed right now!
Love the video, keep it up!
Thank you! Keep up the good work!
nice system. thank you for all your hard work
I’m about to get into making a unity game, would you be able to make a more recent tutorial? Like how to do x. Anything would help!
Thank you! Awesome tutorial!
Im sure it will be useful for me))
Wish I could make art like yours
I gotta love your videos :3
Great video!
The also an idea about next tutorial could be about, I was thinking about weapon system where you are able to improve your weapon increase the damage of bullets or something like also I had in my mind tutorial about sword attack system like Idoz made in his game called archvale or even explain how to make a shop or quest systems.
That Video is very helpfull thank you so much!!!❤❤
Hello. I wanted to know if you could explain to me how to create a weapon system and metal slug type vehicle handles in game maker 2 thanks
Please still do the card game tutorial!
Thank you for the tutorial
Hey Noa Bro if you have time please make tutorials on card making games like you jave created at hallowan
Thanks for the video. I was really needing it. But currently I am facing a problem which is that how to collect the crafted item into the inventory. If someone know it, could you please give me suggestion? Thanks
Good video
These video with a lot of code it's my favorite type video
you should make a game about being a hummingbird who has to use flowers to refuel
lil bro is using strings AND looping through strings AND relying on same index to find the result on a different list NAAAAAAH AINTNOWAY
youtube never disappoints with the goofy ah codes
Great tutorial just one question. Does it work with your inventory tutorial?
Damn you made this video quickly
Thank you my teacher
Very good tutorial
When I tried "public Item item;" I am having an error on Item CS0246 how can I solve this?
How could I make this work with your inventory video?
Inventory System for the next video please 🙏🙏🙏
why cant i see anything on my game, but i can see everything in my scene
Is there any way for us to access the initial resource?
can anyone help me, i want to move items from inventory to crafting
What if I need more than 1 number in a combination?
How can I access these codes ? For reference purpose ?
Next plzz make the Card game
In my opinion, the worst thing about this tutorial, or the overall approach to organising a crafting system this way, is using strings to store the recipes. Not only is it susceptible to spelling errors but also the very assumption that the player would drag and drop the items in the order described in the recipe is naïve because the string-building process is dependent on the order of the resources in the slots instead of what they actually are. Wouldn't it make much more sense to check the type and the quantity of the resources in the slots and then loop through all the existing recipes and check if the types and quantities of the resources match any recipe?
Not to mention that all the logic runs in the Update methods where, to make things worse, you're using GetComponent methods.
I would've added a Craft button or something that would call a method that gets all the resources in the slots, adds them to a class or a struct, passes it to another method that determines if anything can be crafted from the received resources and if so returns the crafted item.
I might investigate the code myself as well and see what's out there that's up to date, I think you do have a point about his use of strings and GetComponent. I realise strings are generally frowned upon when it comes to code efficiency because of the searches you have to do but with GetComponent code it can be done efficiently if it's setup the right way. Seems like it might be a good idea for BlackThorn to do an update video on this just to issue some corrections, if not, then people can post corrections in the comments page.
Can anyone of you please Guide That How do I complete my project very quickly. For example I was working for 1years in Game Development And Made a Ludo(Dummy)Game And Now working on a Project Of Chess Game for Last 7 months of Time with 4hrs a day But I have Done A little Of work Till Now But When I was Making I taught that it this or this work is so simple Just take up only a few minutes But It take 3 -6 Days but even I left something Out Can Any one of You Have the solution of this If yes Then please suggest me Because There are Better experience Game developer Than me
Очень понравилось. Жду с нетерпением следующие уроки👍
How to make 2d portal
2d running game like subway surfer
😀
Hey, if you're looking to just make a general teleporting mechanic, it's actually quite straightforward, do a collision check on whatever your 'portal' gameobject is as your player is running through, then use something like transform.position = portal.transform.position to instantly move your player there once the player collides with the portal gameobject. You can also use this method if you're wanting to teleport a player with the mouse, just adapt the code to a raycast hit position. The way I would do it is attach a script to the portal itself and keep track of the connected portal you want the player to go to that way.
@@lethn2929 thanksss a lot brooo , am newbie so....
Nice tutorial but was too fast, by that I mean that when I understand the point at hand, you'd be in the middle of the next
please slow down your speed. I cant understand anything.
nothing is working for me bro be more specific
Skill issue
AND FREEDOM
this guy was capping the capitalization DOES matter
I clicked on this to see how you'd handle recipes but this method isn't great. It way too strict. the order will need to match. So you could do woodwoodstone but not woodstonewood etc. You also can't reorganize your recipes easily due to 2 lists that must match the order in the inspector. or let alone change the name of an ingredient.
NEXT IS CARD GAME
Hello
Normally I like your content, but this recipe system just gave me cancer. Working with strings when not necessary is something everybody should avoid at all costs.
Please next time look up beforehand how other devs handle your topic. Giving items the recipe in Form of an array of other items, or make a recipe containing the item to create and an array of items needed would be two way better options.
This is 70 comment so i detroyed 69
yg bener aja mas
doesnt work at all
nothing u did works at all, show the whole SCREEEEEENNNN AND SHOW EVERYTHINGGG YOU DOOOOOOOOOOOO WHY SKIP STEEEEEPPSSSSS AND ZOOOOM IN ON EVERYTHINGGGGG
Talk normally holy shit
Rare L, this isnt good
I made a bit of a difference so you get the new item ... and the dragging does things better any questions ask
Crafting manager :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CraftingMan : MonoBehaviour
{
private Item currnetitem;
public Image cursorCus;
public Slots[] craftingslots;
public GameObject[] result;
public List itemlist;
public string[] recipe;
public Item[] repiperesult;
public Slots resultslot;
bool isitin = false;
private void Update()
{
if (Input.GetMouseButtonUp(0))
{
if (currnetitem != null)
{
if (!isitin)
{
currnetitem = null;
cursorCus.gameObject.SetActive(false);
return;
}
if (isitin)
{
Debug.Log(isitin);
cursorCus.gameObject.SetActive(false);
Slots nearestslot = null;
float shortdistance = float.MaxValue;
foreach (Slots slot in craftingslots)
{
float dis = Vector2.Distance(Input.mousePosition, slot.transform.position);
if (dis < shortdistance)
{
shortdistance = dis;
nearestslot = slot;
}
}
nearestslot.gameObject.SetActive(true);
nearestslot.GetComponent().sprite = currnetitem.GetComponent().sprite;
nearestslot.GetComponent().SetNativeSize();
nearestslot.item = currnetitem;
nearestslot.GetComponent().color = Color.white;
itemlist[nearestslot.index] = currnetitem;
currnetitem = null;
Checkforrecp();
}
}
}
}
void Checkforrecp()
{
resultslot.gameObject.SetActive(false);
resultslot.item = null;
string currnetrecpiestring = "";
foreach(Item item in itemlist)
{
if (item != null)
{
currnetrecpiestring += item.name;
}
else
{
currnetrecpiestring += "null";
}
}
for (int i = 0; i < recipe.Length; i++)
{
if (recipe[i] == currnetrecpiestring)
{
resultslot.gameObject.SetActive(true);
resultslot.GetComponent().sprite = repiperesult[i].GetComponent().sprite;
resultslot.GetComponent().SetNativeSize();
resultslot.item = repiperesult[i];
result[i].SetActive(true);
}
}
}
public void INIT()
{
isitin = true;
}
public void OFFIT()
{
isitin = false;
}
public void OnclickSlot(Slots slot)
{
slot.item = null;
itemlist[slot.index] = null;
slot.gameObject.SetActive(false);
Checkforrecp();
}
public void OnmouseDOwnItem(Item item)
{
if (currnetitem == null)
{
currnetitem = item;
cursorCus.gameObject.SetActive(true);
cursorCus.sprite = currnetitem.GetComponent().sprite;
cursorCus.GetComponent().SetNativeSize();
}
}
}
What if I need more than 1 number in a combination?