Adding points to Collider as element of a list.
Hello Community, I want to give my EdgeCollider2d points and it works when it's not a list element. But I want to have multiple EdgeCollider2ds on my object which are listed. Here is my code:
List<EdgeCollider2D> col = new List<EdgeCollider2D>();
List<Vector2> newVertices = new List<Vector2>();
// Use this for initialization
void Start () {
col[0] = GetComponent<EdgeCollider2D>();
newVertices.Add(new Vector2(0, 0));
newVertices.Add(new Vector2(1, 0));
setPoints();
getPointsToDebug();
}
void setPoints()
{
col[0] = gameObject.AddComponent<EdgeCollider2D>();
col[0].points = newVertices.ToArray();
}
void getPointsToDebug()
{
foreach (Vector2 piste in col[0].points)
{
Debug.Log(piste);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612125929im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Deleting an object from a list of objects from another script. 1 Answer
Sort a list of class by a vector variable in the class 2 Answers
List<>.Add : Object reference not set to an object, but nothing is null 1 Answer
Component field instance issues - field changes affect all objects with component 0 Answers
What is the most effective way to structure Card Effects in a Single Player game? 1 Answer