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 Benifir · Jul 22, 2013 at 12:50 AM · error-message

Substute for Array.length?

I am translating a script from the Unity Wiki from Javascript to C#. The other scripts I have got working properly, but I've run into a few problems here that I have not been able to find a work around for. I get three errors for which I cant think of a way to fix:

  1. Assets/First-Third Person Framework/Scripts/GunParticles.cs(13,28): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

  2. Assets/First-Third Person Framework/Scripts/GunParticles.cs(26,57): error CS1061: Type System.Array' does not contain a definition for length' and no extension method length' of type System.Array' could be found (are you missing a using directive or an assembly reference?)

  3. Assets/First-Third Person Framework/Scripts/GunParticles.cs(28,34): error CS0021: Cannot apply indexing with [] to an expression of type `System.Array'

The converted code -

 using UnityEngine;
 using System;
 using System.Collections;
 
 public class GunParticles : Gun {
     private bool _cState;
     private Array emitters; 
 
     // Use this for initialization
     void Start () {
         _cState = true;
         
         emitters = Gun/capsuleEmitter;
         
         ChangeState(false);
     }
 
     public void ChangeState(bool p_newState)
     {
         if(_cState == p_newState) return;
         
         _cState = p_newState;
 
         if(emitters != null)
         {
             for(int cnt = 0; cnt < emitters.length; cnt++)
             {
                 (emitters[cnt] as ParticleEmitter).emit = p_newState;
             }
         }
     }
 }

Any suggestions would be greatly appreciated. Thank you.

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

Answer by Benproductions1 · Jul 22, 2013 at 01:45 AM

Array as such, only exists in Javascript. And even there it should never EVER be used. Use Generic Lists instead

Comment
Add comment · Show 3 · 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 Benifir · Jul 22, 2013 at 06:05 PM 0
Share

Actually, if you call "using System;" you get the Array just as that. Default you can use ArrayList in C# without using the system call. I agree with you that there are better ways than using an Array.

avatar image Benproductions1 · Jul 22, 2013 at 10:52 PM 0
Share

The problem with Array is that it is basically a slow List<object>. There is no point to it's existence and it should be deprecated :)

avatar image Benifir · Jul 22, 2013 at 11:57 PM 0
Share

In that case, I'll have to play around with List sometime and see how I like it. Thanks for the advice! :)

avatar image
0

Answer by Adamcbrz · Jul 22, 2013 at 01:22 AM

1) I need more context for what this line is doing. You may need a get component or find

2) c# Array.Length not lowercase

3) really you need to declare the array like private ParicleEmitter[] emitters.

See if you fix those then let me know what errors you get.

Comment
Add comment · Show 1 · 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 Benifir · Jul 22, 2013 at 05:54 PM 0
Share

1) This script inherits from another script I translated that allows the user to create various guns with different powers, ranges...ect.

2) Using Array.Length still gives off the error that System.Array can't apply indexing

3) In the inherited script I have the variable ParticleEmitter[] capsuleEmitter;

Thanks for the assistance, as soon as i get the kinks worked out I will post the C# version back on the UnityWiki for anyone to use.

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

17 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

Related Questions

Copying file failed (Unable to build) 4 Answers

Error Message 2 Answers

[JavaScript Error] BCE0043: Unexpected token: 2 Answers

I keep getting an error and I don't know how to fix it. 0 Answers

I have an error "MissingReferenceException" and i dont know why 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