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 Avash · Jan 02, 2015 at 05:14 PM · c#mesharray

Few problems with arrays

 for(int ib = 0; ib <= currentCollider.transform.gameObject.GetComponent<MeshFilter>().mesh.triangles.length / 3; ib ++){
 
 

Assets/Game_scripts/GridController.cs(49,150): error CS1061: Type int[]' does not contain a definition for length' and no extension method length' of type int[]' could be found (are you missing a using directive or an assembly reference?)

 aPoints[] = GroundObject.GetComponent<MeshFilter>().mesh.vertices.Skip(i - 1 * 3).Take(3); 


Assets/Game_scripts/GridController.cs(51,57): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer

EDIT:

 foreach (Vector3 tempPosition in tempPositionsList){
             GroundObject.transform.position = tempPosition;
             bool isFree = true;
                 // Check is object free space WIP
             Collider[] hitColliders = Physics.OverlapSphere(GroundObject.transform.position, GroundObject.collider.bounds.extents.magnitude);
             foreach(Collider currentCollider in hitColliders){
                 if(GroundObject.collider.bounds.Intersects(currentCollider.bounds)){
                     int adjustedTriangleCount = currentCollider.transform.GetComponent<MeshFilter>().mesh.triangles.Length / 3;
                     for(int i = 0; i <= adjustedTriangleCount; i ++){    // For every triangle in GroundObject...
 
                         for(int ib = 0; ib <= adjustedTriangleCount; ib ++){    // For every triangle in other object...
                             int[] aPoints = new int[3];
                             aPoints[] = GroundObject.GetComponent<MeshFilter>().mesh.vertices.Skip(i - 1 * 3).Take(3); 
                             Vector3 a1 = GroundObject.transform.TransformPoint(GroundObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[1]]);
                             Vector3 a2 = GroundObject.transform.TransformPoint(GroundObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[2]]);
                             Vector3 a3 = GroundObject.transform.TransformPoint(GroundObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[3]]);
                             int[] bPoints = new int[3];
                             bPoints[] = GroundObject.GetComponent<MeshFilter>().mesh.vertices.Skip(i - 1 * 3).Take(3); 
                             Vector3 b1 = currentCollider.transform.TransformPoint(currentCollider.transform.gameObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[1]]);
                             Vector3 b2 = currentCollider.transform.TransformPoint(currentCollider.transform.gameObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[2]]);
                             Vector3 b3 = currentCollider.transform.TransformPoint(currentCollider.transform.gameObject.GetComponent<MeshFilter>().mesh.vertices[aPoints[3]]);
                             if(TriTriOverlap.TriTriIntersect(a1, a2, a3, b1, b2, b3)){
                                 isFree = false;
                             } 
                         }
                     }
             }
             } 
             if(isFree != false){
                 possiblePositionsList.Add (tempPosition);
             }
         }

Comment
Add comment · Show 1
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 Giannigiardinelli · Jan 02, 2015 at 05:30 PM 0
Share

I think that the writing is not good you have to use what like variable for aPoints ?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Anxo · Jan 02, 2015 at 05:39 PM

First, use Length not length, and I would optimize so you are not making the count every time by just making it once before the loop.

 int adjustedTriangleCount = currentCollider.transform.GetComponent<MeshFilter<().mesh.triangles.Length / 3;

 for (int ib = 0 ; i < adjustedTriangleCount ; i++){
 
 }


WUCC

Comment
Add comment · Show 6 · 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 Avash · Jan 02, 2015 at 06:12 PM 0
Share

Ok, what about the other problem?

avatar image Anxo · Jan 02, 2015 at 07:36 PM 0
Share

Skip in namespace Linq is interesting but not something I see with Unity's array class. $$anonymous$$aybe if you use List ins$$anonymous$$d you may have more luck, I am also not sure what you are trying to do with that line, if you explain your intentions, I would be happy to share an alternative path.

avatar image Avash · Jan 02, 2015 at 08:03 PM 0
Share

I need to get every triangle and get vertices.

avatar image Avash · Jan 02, 2015 at 08:08 PM 0
Share

So I need to convert vertices to a list first. Doesn't that cost cpu? Is there any other solutions?

avatar image Anxo · Jan 02, 2015 at 08:13 PM 0
Share

Its not too CPU heavy unless you have thousands of verts, all depends on how heavy your model is. But what is it you are trying to do with this line.

  aPoints[] = GroundObject.GetComponent<$$anonymous$$eshFilter>().mesh.vertices.Skip(i - 1 * 3).Take(3); 

$$anonymous$$aybe we can point you in another direction to accomplish the same thing.

Show more comments

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

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A problem with intersection detection 1 Answer

Array index out of range error 1 Answer

A problem with arrays 1 Answer

Toggle Control between multiple turrets 0 Answers

Picking a Random Order for Levers 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