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 fred_gds · Mar 27, 2013 at 07:44 PM · arrayclassaddsortremoveat

class array removeAt

Hey,

I created a custom class in unityscript. Like that:

class MyClass { var one : int; var two : int; }

then I created a variable

var myClassVariable : MyClass[] = new MyClass[5]; function Start() { for(var i : int = 0; i < myClassVariable.length; i++) { myClassVariable[i] = new MyClass } }

so and then later on I wanted to delete myClassVariable[0] and to add a new value to the end of the variable like that

myClassVariable.RemoveAt(0); myClassVariable.Add(myValueToAdd);

But unity tells me that RemoveAt and Add aren't part of MyClass.

Could anyone give me either a method which allows me to remove the first value of an array and to add a new value at the end (so something similar to RemoveAt and Add) or explain to me how to get those functions to work on a custom class?

Best regards,

Fred

Comment
Add comment · Show 4
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 whydoidoit · Mar 27, 2013 at 07:46 PM 0
Share

You should use a List.< $$anonymous$$yClass> if you want to add and remove them. See this

avatar image fred_gds · Mar 27, 2013 at 09:17 PM 0
Share

Sorry to ask. But what is the differnce between a List. and an array? and the link you porvided doesn't handle this subject

avatar image whydoidoit · Mar 27, 2013 at 09:18 PM 0
Share

Lists can be added to and removed from at runtime. Arrays cannot. Otherwise the semantics [] are the same, but Length becomes Count.

avatar image Eric5h5 · Mar 27, 2013 at 09:20 PM 0
Share

http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fred_gds · Mar 27, 2013 at 09:46 PM

I tried the list thing but I already have too much stuff depending on that array and I don't want to rewrite everything. So I wanted to write smth like this:

if(GUI.Button ....) { changeClass(); } function changeClass() { myClass[0] = myClass[1]; myClass[1] = myClass[2]; myClass[2] = myClass[3]; myClass[3] = myClass[4];

 myClass[4].amount = number;

}

so the button can only be pressed once for each car (its from a car game).

Lets start as I have it. So at the beginning all values equal 0 and the value number changes everytime the script gets called.

Then I press the button once and the function gets called. Then it returns me the same value for myClass[3] and myClass[4].+

And if the function gets called again myClass[3], myClass[4] and myClass[2] equal the same value and so on. But I can't find the reason why it's doing this as the script doesn't allow it.

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

12 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

Related Questions

Add custom declared variables in a Array 1 Answer

C# Adding to an Array 1 Answer

Help with sorting values from a class 2 Answers

Custom Sort class array error if i use #pragma 2 Answers

Script wont read array 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