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
1
Question by Slavrix · Feb 23, 2014 at 01:59 PM · gameobjectslists

adding components to a gameObject in a list of lists

im trying to add components to a gameobject thats inside a list of lists,

im getting the error

Assets/createplane.cs(151,71): error CS1061: Type System.Collections.Generic.List' does not contain a definition for AddComponent' and no extension method AddComponent' of type System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)

the error is on the line

MeshFilter meshFilter = (MeshFilter)thePlanes[(int)z].AddComponent(typeof(MeshFilter));

i think im not accessing the .addcomponent of the gameobject in the list properly, but im not sure,

 List<List<GameObject>> thePlanes;
 
 void Awake()
     {
         List<List<GameObject>> thePlanes = new List<List<GameObject>>();
         
         for(float i = 0;i<planecount;i++)
         {
             thePlanes.Add(new List<GameObject>());
             
             for(float j = 0;j<planecount;j++)    
             {
                 MakePlane(i,j);
             }
         }
     }
 
 void MakePlane(float x, float z)
     {
         //GameObject plane = new GameObject("Plane x="+x+" z="+z);
         thePlanes[(int)z].Add(new GameObject("Plane x="+x+" z="+z));
         //MeshFilter meshFilter = (MeshFilter)plane.AddComponent(typeof(MeshFilter));
         MeshFilter meshFilter = (MeshFilter)thePlanes[(int)z].AddComponent(typeof(MeshFilter));
         meshFilter.mesh = CreatePlane(size);
         //MeshRenderer renderer = plane.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
         MeshRenderer renderer = (MeshRenderer)thePlanes[(int)z].AddComponent(typeof(MeshRenderer));
             renderer.material.shader = Shader.Find ("Particles/Additive");
         Texture2D tex = new Texture2D(1, 1);
         tex.SetPixel(0, 0, Color.green);
         tex.Apply();
         renderer.material.mainTexture = tex;
            renderer.material.color = Color.green;
         meshFilter.transform.Translate(new Vector3((x*size*(size-1)),0,(z*size*(size-1))));
         //thePlanes[(int)z].Add(plane);
     }

i think ive got it correct, im doing it the same way i was doing it before i put them in the list, but its not working for this

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 KiraSensei · Feb 23, 2014 at 02:00 PM 0
Share

What is not working ? Do you have an error or the behavior is not what you expected ?

2 Replies

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

Answer by Slavrix · Feb 23, 2014 at 03:06 PM

I solved my problem, I wasn't referencing the correct item in the list, in several places.

  void Awake()
         {
             thePlanes = new List<List<GameObject>>();
             
             for(float i = 0;i<planecount;i++)
             {
                 thePlanes.Add(new List<GameObject>());
                 for(float j = 0;j<planecount;j++)    
                 {
                     MakePlane(i,j);
                 }
             }
         }
         
         void MakePlane(float x, float z)
         {
             //GameObject plane = new GameObject("Plane x="+x+" z="+z);
             thePlanes[(int)x].Add(new GameObject("Plane x="+x+" z="+z));
     
             //MeshFilter meshFilter = (MeshFilter)plane.AddComponent(typeof(MeshFilter));
             MeshFilter meshFilter = (MeshFilter)thePlanes[(int)x][(int)z].AddComponent(typeof(MeshFilter));
             meshFilter.mesh = CreatePlane(size);
             //MeshRenderer renderer = plane.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
             MeshRenderer renderer = (MeshRenderer)thePlanes[(int)x][(int)z].AddComponent(typeof(MeshRenderer));
                 renderer.material.shader = Shader.Find ("Particles/Additive");
             Texture2D tex = new Texture2D(1, 1);
             tex.SetPixel(0, 0, Color.green);
             tex.Apply();
             renderer.material.mainTexture = tex;
                renderer.material.color = Color.green;
             meshFilter.transform.Translate(new Vector3((x*size*(size-1)),0,(z*size*(size-1))));
             //thePlanes[(int)z].Add(plane);
         }
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 Linus · Feb 23, 2014 at 03:07 PM 0
Share

Updated your answer to be English, and n0t gribrish

avatar image
0

Answer by Bunnybomb7670 · Feb 23, 2014 at 02:39 PM

Try doing MeshFilter meshFilter = ((MeshFilter)thePlanes[(int)z]).AddComponent(typeof(MeshFilter));

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

22 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

Related Questions

Why does the script don't apply to the other duplicated player 0 Answers

How to find all similar elements in a list? 1 Answer

How do i activate a function attached to a listed GameObject from the perspective of itself? 1 Answer

Gather all GameObjects with a certain name in a Scene and Apply them to a list? 3 Answers

List Of GameObjects , Deleting these Objects ! 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