- Home /
How to add elements from a List of another class to another List (C#)
I'm in Unity2D
I have "Script A" with List ListA with "x" elements (childs of GameObject). This Script is attached to the FatherGameObject.
Then I have "Script B" with List ListB with (NO) elements on it. This Script is attached to the Father of the FatherGameObject mencioned.
I want to add the elements from "List A" To "List B" or in someway link the both Lists.
P.D I need to declare it in the Public Class Script B as i need "List B" in lots of others methods.
The two Scripts are Mono Behavior.
Please and Thanks.
Answer by Maerig · May 01, 2014 at 07:42 AM
public GameObject FatherGameObject;
...
List<YourType> ListB = FatherGameObject.GetComponent<Script A>().ListA
Of course, you need to replace ListA with its accessor if it is private.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Player instantiates Backwords 0 Answers
Subtracting the position of transform from the position of Game Objects in a list. 1 Answer
How to select an Game Object from an Item List 0 Answers
How can i get ONLY the childrens of a GameOnbject with GetComponentsInChildren method? 5 Answers