Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by MagicGeek123 · Dec 08, 2013 at 06:23 PM · systemcrafting

Crafting System Help

i need some help i came up with a crafting script that requires a craft table type thing and i need help turning this into a craft anywhere type thing also my current script dosnt work how i want it to since it only needs one of the reguired objects please help HERE IS THE SCRIPT:

pragma strict

var tool : GameObject;

function Start () { tool.SetActive(false); }

function OnTriggerEnter ( Col : Collider) { if(Col.tag == "Rock" ) { tool.SetActive(true); }

 else
 
 if(Col.tag == "Stone" )
     {
         tool.SetActive(true);
     }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by YoungDeveloper · Dec 08, 2013 at 07:39 PM

Every item in every game is located in some sort of list and has an unique index. If you follow these rules, creating any item manipulation should be piece of cake. What you could do is create possible recipe array.

 [ExecuteInEditMode]
 public class Recipes : MonoBehaviour {
 
 [System.Serializable] //So you could input stuff from inspector
 public class Item{
     public int [] ingredients; //set array size and item indexes in inspector
     public int resultItem;   //item index which is crafted
 }
 
 public Item [] recipeList;
 
 }

For this to work you should have other item lists, like for this example, lets have list with such information:

(array index) | (name)

1 apple

2 tomato

3 bread

4 orange

5 cookie

6 weirdMeal

In recipes inspector overall recipes list set to lets say 10, so now you have 10 possible variations. In first slot set ingredients array size to 3, which will mean that you will need 3 items to cook some item, and in result item set which item will be crafted. For example:

1;3;4 and result item 6

All you need now is script which searches/compares (in craft table) inputted indexes to this list, because item can be placed in different order, like 4;1;3. And if it finds recipe, run inventory check if that item can be placed in inventory (in you have such), if it succeeds, remove items inside craft table and spawn item 6, that is "weirdMeal" in your inventory.

Of course combinations can be stored in separate arrays..

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MagicGeek123 · Dec 09, 2013 at 12:59 AM 0
Share

i dont quit understand what you mean hope i dont sound like a total idiot. im used to javascript so i dont quit understand c#. seems good will use just need more of an explanation so i can understand better

avatar image YoungDeveloper · Dec 09, 2013 at 01:26 AM 0
Share

To craft something you first must have those "items", and to identify every item in your game, every item should have a unique number. And to grant every item with a number you can store them in an array, similar as i showed before. When every item is saved in an array you can do with these items whatever you want.

The crafting system i mentioned just reads and searches through those numbers (indexes).

avatar image MagicGeek123 · Dec 11, 2013 at 01:35 AM 0
Share

how do you assign numbers to the objects

avatar image Kiloblargh · Dec 11, 2013 at 01:42 AM 0
Share

He just told you that, in an admirable display of leading-a-horse-to-water. You add them to an array or list. The numbers are the array index. If "array index" doesn't make sense to you, you don't need to be working on a crafting system, you need to be working on learning basic program$$anonymous$$g concepts. You don't have to assign them- although if you did want to manually assign numbers to objects for some reason, you would do so with a Dictionary.< GameObject, int >. )

avatar image YoungDeveloper · Dec 11, 2013 at 02:14 AM 0
Share

@$$anonymous$$iloblargh Yeah, you are right, i pretty much wasted my time trying to explain these things, but i was hoping it would make sense for him. Person who asked the question surely should do some RTF$$anonymous$$ before doing anything near crafting systems.

Show more comments
avatar image
0

Answer by HuskyPanda213 · Mar 09, 2014 at 04:48 AM

I have a working system. It is in c#

 public void Craft(Craftable recipe){
         bool b = CheckItems (recipe.InputItems);
         if(b){//Craft...
 }
 }
 
 public bool CheckItems(List<Item> check) {
         List<Item> it = new List<Item> (check);
         foreach(Item inventoryItem in MyItems) {
             if (it.Contains(inventoryItem)) {
                 it.Remove(inventoryItem);
                 if(it.Count == 0) {
                     return true;
                 }
             }
         }
         return false;
     }

Item, and craftable...

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class Item {
 
     public string itname;
     public float itvalue;
     public float itdur;
     public string ittype;
     public Texture2D iticon;
 
     public override bool Equals(object other) {
         if (other.GetType() != typeof(Item)) return false;
         if (((Item)other).itname == this.itname && ((Item)other).ittype == this.ittype) {
             return true;
         }
         return false;
         //return ((Item)other).itname == this.itname;
     }
 }
 
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Craftable {
 
     public List<Item> InputItems = new List<Item>();
 
     public List<Item> Outputs = new List<Item>();
 
     public bool RequiresWorkBench;
 
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

CRAFTING SCRIPT FOR A SURVIVAL GAME I NEED HELP PLEASE!!! 0 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Need help with my "simple" crafting system 1 Answer

Door and Key System please help 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges