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 /
avatar image
0
Question by pretender · May 14, 2010 at 02:10 PM · arrayraycasthitcopy

Problem with copying array that holds Raycasthit objects

Posted: Fri May 14, 2010 2:34 pm Post subject: Copying an array
it doesn't seem to work...

here is how i tried to do it:

declaration

  var hitObjects : Collider[];
  var hits : RaycastHit[];

copying the array after some objects were hit:

Code:

     for (i=0;i<hits.length;i++) { 
          hitObjects[i] = hits[i].collider; 
     } 

later on i wanted to verify is everything is ok with this in OnGUI function but i get info only for hits[x] not for anything else:

Code:

for(var x=0;x<hits.length;x++){ GUI.Label(Rect(10,10+((x+1)*15),400,30),hits[x].collider.name); }

for(var y=0;y<hitObjects.length;y++){ GUI.Label(Rect(10,40+((y+1)*15),400,30),hitObjects[y].name); }

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 Extrakun · May 14, 2010 at 03:19 PM

Do a check, have you initialize the starting length for the hitObjects array?

After seeing comment: You have to use a Javascript Array, or an ArrayList, which supports dynamic size. You can take a look at this page

Or when using fixed size array

hitObjects = new hitObjects[hits.length];
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 pretender · May 15, 2010 at 07:19 AM 0
Share

no, i thought that it will automatically adjust the size according to the size of the array i am copying, how to do that?

avatar image Extrakun · Jun 08, 2010 at 12:03 PM 0
Share

It is only automatic when you add content to an array through the Inspector. In code, a normal array is not automatic. Look at the link above in the answer above for array lists and other types of collections that can resize on the fly.

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

No one has followed this question yet.

Related Questions

Copy From Array to List without reference [C#] 2 Answers

Array.Copy still creating a reference. 1 Answer

Array.Copy in UnityScript 1 Answer

Get Material of Normal? 0 Answers

How to copy part of an 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