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
0
Question by NutellaDaddy · Apr 04, 2014 at 12:21 AM · c#inventoryitem pickup

Different script for each item?

I have all of these items that I am defining and I wonder if I should have a seperate script for each item because what happens is you find the item on the ground and then you press e on it to pick it up and then when you press E it adds the item to your inventory. Should I put all of the items in one script or make a seperate script for each item? Here's how it looks right now using the same script for each item: using UnityEngine; using System.Collections;

 public class AllItems : MonoBehaviour
 {
     private const string meleeWeaponPath = "Icons/Weapons/Melee";
 
     public static Weapon AllWeapons()
     {
         //MELEE WEAPONS
         Weapon machete = new Weapon (12.5f, 0.0f, 4, false, 0, false);
             machete.name = "Machete";
             machete.description = "A fast bladed weapon";
             machete.icon =  Resources.Load (meleeWeaponPath + machete.name) as Texture2D;;
             machete.rarity = RarityType.Common;
             machete.curDurability = 150.0f;
             machete.maxDurability = 150.0f;
             machete.weightAmount = 1;
 
         Weapon shovel = new Weapon (20.0f, 0.0f, 2, false, 0, false);
             shovel.name = "Shovel";
             shovel.description = "A blunt tool for shoveling the earth.";
             shovel.icon =  Resources.Load (meleeWeaponPath + shovel.name) as Texture2D;;
             shovel.rarity = RarityType.Common;
             shovel.curDurability = 150.0f;
             shovel.maxDurability = 150.0f;
             shovel.weightAmount = 1;
 
         Weapon woodAxe = new Weapon (25.0f, 0.0f, 1, false, 0, false);
             shovel.name = "Wood Axe";
             shovel.description = "A sharp tool for chopping down trees.";
             shovel.icon =  Resources.Load (meleeWeaponPath + woodAxe.name) as Texture2D;;
             shovel.rarity = RarityType.Uncommon;
             shovel.curDurability = 200.0f;
             shovel.maxDurability = 200.0f;
             shovel.weightAmount = 1;
         
         
         //    BASIC RANGED/Rough Craft
 
 
 
 
 
         //GUNS
 
 
 
 
 
         //LASER WEAPONS
 
 
 
 
 
         return null;
     }
     public static Consumable AllConsumables()
     {
         //FOOD
 
 
 
         //LIQUID
 
 
 
 
         //MEDICINE OR HEALTH RELATED
 
 
 
 
 
         return null;
     }
     public static Armor AllArmor()
     {
         //BASIC AND MODERN
 
 
 
 
         //ROUGH CRAFT
 
 
 
 
         //POWER OR ADVANCED
 
 
 
 
 
         return null;
     }
     public static Placeable AllPlaceables()
     {
         //BUILDINGS
 
 
 
 
         //STATIONS
 
 
 
 
         return null;
     }
         public enum ItemType
         {
             Armor,
             Weapon,
             Consumable,
             Placeable
         }
 }

Just want to know what you guys would thing would be the best or easiest! Tell me if you have any other ideas.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by HuskyPanda213 · Apr 04, 2014 at 12:54 AM

I would think it is ok as is. Just you should make allitems a static class, instead of one inheriting from MonoBehaviour.

The problem comes when you need to assign the items in the game world. How I would go about this is create a GameObject[] or whatever array. Then when you switch item, check the name of the item, and if it matches with the name of the other item, set it active, else set it inactive.

Then, that gives you the flexibility to make different scripts for different items, but only when needed. Note(about the GameObject[] Part): I would probably not make a different script for every item, I would more make the script called MeleeWeapon which is heavily customizable and so on.

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

21 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 avatar image avatar image

Related Questions

Is there a way to shorten these? 1 Answer

error CS1526: A new expression requires () or [] after type 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Hotbar and item pickups? 1 Answer

Starting out C# help 2 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