Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed May 23, 2016 at 02:21 AM by TBruce for the following reason:

Duplicate Question - http://answers.unity3d.com/questions/1190802/got-a-few-errors-with-my-inventory-any-ideas.html#answer-1190855

avatar image
0
Question by 22ecvvw · May 23, 2016 at 01:57 AM · error

Error with classes

 using UnityEngine;
 using System.Collections;
 
 public class InvM_Lab3 : MonoBehaviour {
 
     PF1_IO myIO; 
     LAA_Inventory inv = new LAA_Inventory();  
     LAA_Items tempItems; 
     LAA_Weapons tempWeapons; 
     LAA_Defense tempDefense;  
 
 
 
     enum STATE {none, name, value, att_def, inputItem };
 
     STATE curState = STATE.none;
 
 
     string iName = "";
     int value = 0;
     int att_def = 0;
 
 
 
 
 
     string userInput;
 
 
     void Start () {
         myIO = PF1_IO.pf; 
 
         printInventory();
 
     }
 
 
     void Update () {
 
 
         string sInput = ""; 
 
         int itemp = 0;
 
 
         if(myIO.IsThereInput()){
             sInput = myIO.getString();
 
             itemp = myIO.getInteger();
 
             myIO.ClearPreviousInput();
 
 
         }
 
         switch(curState){
 
         case STATE.name:
             myIO.replaceText("Please enter a name for the item.");
 
             if(sInput != ""){
                 print(sInput);
                 iName = sInput;
                 curState = STATE.value;
             }
             break;
 
         case STATE.value:
             myIO.replaceText("Item Name: " + iName + "\nPlease enter a value for the item.");
 
             if(itemp > 0){
                 value = itemp;
                 itemp = 0;
                 curState = STATE.att_def;
             }
             break;
 
         case STATE.att_def:
             myIO.replaceText("Item Name: " + iName + "\nItem Value: " + value + "\n");
 
         
             if(userInput == "weapon")
                 myIO.appendText("Please enter a weapon for the item.");
         
             else if(userInput == "defense")
                 myIO.appendText("Please enter a defense for the item.");
 
             if(itemp > 0){
                 att_def = itemp;
                 itemp = 0;
                 curState = STATE.inputItem;
             }
             break;
 
         case STATE.inputItem:
 
             if(userInput == "weapon" ){
                 tempWeapons = new LAA_Weapons (value, att_def, iName); 
 
 
                 inv.AddItem(tempWeapons); 
 
                 myIO.replaceText("Your item has been added to your inventory!");
 
                 WouldYouLikeTo(); 
             }
 
             if(userInput == "defense" ){
                 tempDefense = new LAA_Defense (value, att_def, iName);  
 
 
                 inv.AddItem(tempDefense);
 
                 myIO.replaceText("Your item has been added to your inventory!");
 
                 WouldYouLikeTo();
             }
             break;
 
         case STATE.none:
             string temp = sInput.ToLower();
 
 
             if(temp == "weapon" || temp == "defense"){
 
                 print(sInput);
                 userInput = temp;
                 sInput = "";
                 curState = STATE.name;
             }
             else if(temp == "inventory"){
                 printInventory();
                 sInput = "";
             }
             break;
 
         }
 
 
 
 
     }
 
     void printInventory(){
 
 
         myIO.replaceText("You currently have " + inv.getInventoryTotal() + 
             " items in your inventory. Consisting of:\n");
 
 
         for (int i = 0; i < inv.getInventoryTotal (); i++) {
             if (inv.GetAutoAt (i).GetType == "weapons")
                 tempWeapons = (LAA_Weapons)inv.GetAutoAt (i);
             myIO.appendText (tempWeapons.sendInfo ());
         }
 
         for (int i = 0; i < inv.getInventoryTotal (); i++) {
             if (inv.GetAutoAt (i).GetType == "defense")
                 tempWeapons = (LAA_Defense)inv.GetAutoAt (i);
             myIO.appendText (tempDefense.sendInfo()); 
         }
 
         WouldYouLikeTo();
 
 
     }
 
     void WouldYouLikeTo(){
 
 
         myIO.appendText("\n\nWould you like to add another type of \"weapon\" or \"defense\" item to your inventory?" +
             "\n\tOr would you like to see your \"inventory\" again?");
 
         curState = STATE.none;
 
         iName = "";
         value = 0;
         att_def = 0;
         userInput = "";
 
     
 
         tempItems = null;
         tempWeapons = null;
         tempDefense = null;
 
     }
 
 }
Comment
Add comment · Show 5
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 22ecvvw · May 23, 2016 at 01:57 AM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class LAA_Items  {
 
     string Items; 
     string command; 
      
 
     public LAA_Items () {
         Items = ""; 
         command = "";
 
     }
 
     public LAA_Items (string i, string c) {
         Items = i;
         command = c;
 
     }
 
     public void setItems (string i) {
         Items = i;
 
     }
 
     public void setcommand (string c) {
         command = c;
 
     }
 
     public string getItems () {
         return getItems ();
 
     }
 
     public string getcommand () {
         return getcommand ();
 
     }
 }
 
 
 
avatar image 22ecvvw · May 23, 2016 at 01:57 AM 0
Share

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class LAA_Inventory {

 public List<LAA_Items> WEA$$anonymous$$ = new List<LAA_Items>();

 public LAA_Inventory()
 {
     LAA_Weapons temp = new LAA_Weapons();

     WEA$$anonymous$$.Add(temp);
 }
 public void AddItem(LAA_Items auto)
 {
     WEA$$anonymous$$.Add (auto);
 }
 public LAA_Items GetAutoAt(int i)
 {
     return WEA$$anonymous$$ [i];
 }
 public int getInventoryTotal()
 {
     return WEA$$anonymous$$.Count;
     }

}

avatar image 22ecvvw · May 23, 2016 at 01:58 AM 0
Share

using UnityEngine; using System.Collections;

public class LAA_Weapons : LAA_Items {

 int damage;
 int ammosize;

 public LAA_Weapons()
 {
     this.Type = "Weapon";
     this.Name = "Assualt Rifle";
     this.Price = 750;
     damage = 100;
     ammosize = 25;

 }
 public LAA_Weapons(string n, int p, int d)
 {
     this.Type = "Weapon";
     this.Name = n;
     this.Price = p;
     damage = d;
     ammosize = 0;
 }
 public int getDamage()
 {
     return damage;
 }
 public int getAmmosize()
 {
     return ammosize;
 }

 public string sendInfo ()
 {
     string send;

     send = "\nname: " + this.Name + " price " + this.Price + " damage " + this.damage;

     return send;
 }

}

avatar image 22ecvvw · May 23, 2016 at 01:58 AM 0
Share

using UnityEngine; using System.Collections;

public class LAA_Defense : LAA_Items {

int strength; int damage;

public LAA_Defense () { this.Type = "Defense"; this.Name = "Armor"; this.Price = 750; strength = 100; damage = 25;

}

public LAA_Defense (string n, int p, int s){

 this.Type = "Defense"; 
 this.Name = n;
 this.Price = p;
 strength = s;
 damage = 0;

}

public int getStrength() { return strength; }

public int getDamage() { return damage; }

public string sendInfo() { string send; send = "\nname:" + this.Name + "price:" + this.Price + "strength:" + this.strength; return send;

} }

avatar image 22ecvvw · May 23, 2016 at 01:59 AM 0
Share

alt text

screen-shot-2016-05-22-at-95856-pm.png (208.7 kB)

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

61 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 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 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

The content was stopped because a fatal content error has been detected(HELP) 0 Answers

Error 0xc000007b when starting unity.exe 4 Answers

Parsing error CS8205,Parsing Error CS8205 2 Answers

Keeping points tallied 1 Answer

NullReferenceException: Object reference not set to an instance of an object ? 0 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