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 Starside · Dec 08, 2013 at 09:45 AM · argumentexceptions

ArgumentOutOfRangeException: Argument is out of range? What wrong?

Well I've tried every thing I know (which isn't much considering I'm a noobie) to fix this. Can some one help me fix the Error. Here is my code ItemClass:

 public class ItemClass
 {
 public var name : String;
 public var description : String;
 public var icon : Texture2D;
 public var itemType : ItemType;
 enum ItemType{None, Weapon, Other}
 
 }`

Inventory Script

 import System.Collections.Generic;
 
 var playerInventory : List. = new List.();
 var scrollView : Vector2;
 var Weapon : ItemClass;
 var equipped : boolean = false;
 
 function Update () {
 
 }
 
 function OnGUI () 
 {
 
     GUILayout.BeginArea(Rect(Screen.width - 100,0,100,100));
 
     scrollView = GUILayout.BeginScrollView(scrollView, GUILayout.Width(100), GUILayout.Height(100));
     for(var x = 0; x < playerInventory.Count; x++)
     {
 
     GUILayout.BeginHorizontal();
         if(GUILayout.Button(playerInventory[x].icon))
         {
             playerInventory.RemoveAt(x);
             return;
         }
         GUILayout.Box(playerInventory[x].name);
         GUILayout.EndHorizontal();
         GUILayout.Box(playerInventory[x].description);
     }
     GUILayout.EndScrollView();
     GUILayout.EndArea();
 
     if(GUI.Button(Rect(Screen.width/2 - 25, Screen.height - 50,50,50), Weapon.icon)){
 
 
         }
     
     }`

AddItem Script:

 import System.Collections.Generic;
 
 var loot : ItemClass[];
 var Inventory : Inventory;
 
 function Start () {
 Inventory = GetComponent("Inventory") as Inventory;
 }
 
 function OnGUI () {
 
 GUILayout.BeginArea(Rect(0,0,60,60));
 if(GUILayout.Button("loot"))
     {
         giveloot();
     }
 GUILayout.EndArea();
 
 }
 
 function giveloot() {
 
 for(var x = 0; x < loot.length; x++)
 Inventory.playerInventory.Add(loot[x]);
 }

These are the three scripts I am using to make an Inventory. Any help would be appreciated. Thanks in Advanced.

Comment
Add comment · Show 8
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 meat5000 ♦ · Dec 08, 2013 at 09:47 AM 0
Share

You need to reformat your code :)

Also, which line is the error on? (After reformatting, so we can see the line number properly)

avatar image tomekkie2 · Dec 08, 2013 at 09:50 AM 0
Share

First, check on the console where - what line - that precisely happens

avatar image meat5000 ♦ · Dec 08, 2013 at 10:00 AM 0
Share

Click EDIT under the tags, under the question. Highlight all the code (dragging from bottom to top seems to work better than top to bottom) and click 101010 button

avatar image Starside · Dec 08, 2013 at 10:03 AM 0
Share

Reformatted It doesn't say what line it's on

avatar image meat5000 ♦ · Dec 08, 2013 at 10:06 AM 0
Share

Just copy and paste the whole error from the Unity console

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by meat5000 · Dec 08, 2013 at 10:20 AM

It depends if you know how big your array needs to be.

 var loot = new ItemClass[size];

I have previously declared a 0 size array and expanded it when needed but this isn't very efficient:

 var loot = new ItemClass[0];

To resize by one:

 System.Array.Resize.<int>(loot, loot.Length + 1);

You may have to replace int with your own Type, ItemClass. I've never tried using a Custom array type, so you may have to experiment a bit!

Comment
Add comment · Show 2 · 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 Starside · Dec 08, 2013 at 10:31 AM 0
Share

Thanks it worked

avatar image meat5000 ♦ · Dec 08, 2013 at 10:40 AM 0
Share

Good Good :) Please accept the answer by clicking the tick

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

18 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

Related Questions

A node in a childnode? 1 Answer

How to use unlimited parameters in a function? (JS) 1 Answer

Unity array out of range exception, using photon unity network. 1 Answer

changing a coroutine's argument at the coroutine's runtime? 1 Answer

Disable Mac OSX 'Active Screen Corners' 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