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 DasFloX · Jun 16, 2013 at 10:55 AM · javascriptclassweaponsgeneric list

ArgumentOutOfRangeException - Generic List - Javascript

Hi, I am making a Sidescroller-Shooter Game and im at the point, where i want to add multiple Weapons to my player, that I can switch through. So I used a Generic list to this, which has the variables, that need to be assigned in it.

 public class Weapons
 {
 
      public var name : String = "Weapon";
      public var firemode : fMode = fMode.semi;
      public var firerate : float = 0.1f;
      
     
      public var model : Transform;
      public var raystart : Transform;
      public var muzzle : GameObject;
      public var muzzlelight : Light;
 }

I Better show you the full script, so you can see it better.

 #pragma strict
 import System.Collections.Generic;
     
     private var muzzletime : float = 0.1;
     public var CurrentWeapon : Weapons;    //Here i got the List defined
     public var weapons : List.<Weapons>;   //CurrentWeapon is for the Weapon in hand
     weapons = new List.<Weapons>();
 
     
 
     // Use this for initialization
     function Start () {
     weapons.Capacity = 2;
         Debug.Log("möglich" + weapons.Capacity + ", drin" + weapons.Count);
         CurrentWeapon.muzzlelight.light.enabled = true;
         CurrentWeapon = weapons[0]; //here i choose a list entry || It says the Mistake is here
     
     }
     
     // Update is called once per frame
     function Update () {
     
         Muzzlecontroll();
     }
     
     function Shoot (i : int) {
     
     if(Input.GetMouseButtonDown(i) && CurrentWeapon.firemode == fMode.semi){
 
         if(Physics.Raycast(CurrentWeapon.raystart.position, CurrentWeapon.raystart.TransformDirection(Vector3.forward), 20)){
             Debug.DrawRay(CurrentWeapon.raystart.position,CurrentWeapon.raystart.TransformDirection(Vector3.forward) * 10,Color.red);
             Debug.Log ("Something was hit");
             
         }
         CurrentWeapon.model.animation.Play("Recoil");
         CurrentWeapon.muzzle.renderer.enabled = true;
         muzzletime = 0.1;
         CurrentWeapon.muzzlelight.light.enabled = true;
     }
 
         if(muzzletime < 0){
         CurrentWeapon.muzzle.renderer.enabled = false;
         }
     }
     
 function Muzzlecontroll () {
 
         if(muzzletime >= 0.0){
         muzzletime -= Time.deltaTime;
         }
             if(muzzletime < 0){
         CurrentWeapon.muzzle.renderer.enabled = false;
         CurrentWeapon.muzzlelight.light.enabled = false;
         }
     
 
 }
 
 public enum fMode
 {
     rocketlauncher,
     auto,
     semi,
     bolt
 }
 
 public class Weapons //<--- The weapon class
 {
 
      public var name : String = "Weapon";
      public var firemode : fMode = fMode.semi;
      public var firerate : float = 0.1f;
      
     
      public var model : Transform;
      public var raystart : Transform;
      public var muzzle : GameObject;
      public var muzzlelight : Light;
 }

Then i fill in the variables in the editor. But if i then want to start the game, it sets my size of the list again to 0, and says: "ArguementOutOfRangeException: Argument is out of Range"

And says the Mistake is there`CurrentWeapon = weapons[0];`

Hopy someone could help me and that my Question is readable. I really need some help.

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
-1
Best Answer

Answer by DasFloX · Jun 16, 2013 at 07:55 PM

It's better to use simple Array in this Case.

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

14 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

Related Questions

Argument out of range - Generic list (JS) 2 Answers

Custom JS class error - function is not a member of the class 2 Answers

missingGameObject problem 3 Answers

Public Class Error 1 Answer

Static array with custom class? 1 Answer


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