How to get 2 CircleCollider2d components with the same name in an object in C#?.
I use
CircleCollider2D cir;
void Start ()
{
cir = GameObject.FindWithTag("Plant").GetComponent<CircleCollider2D>();
cir.istrigger = true;
}
but it just affect to the 1st CircleCollider2D only. and I dont know how to use Getcomponents (with s)
Answer by arthymon · Dec 17, 2016 at 07:10 AM
If i understood you correctly you want to get 2 objects , with a mouse click, here's my code , basically i find Gameobject with the name 1 , and then , after i press mouse button i'm getting component circlecollider2d and access to it's istrigger attribute and set it to true , and right after i did that, script is searching for another one circlecollider2d with the name 1 :
void Start () {
obj = GameObject.Find("1");
}
void Update () {
if( Input.GetMouseButton(1)){
obj.GetComponent<CircleCollider2D>().isTrigger = true;
obj = GameObject.Find("1");
}
}
}
No I have an Object with 2 CircleCollider2D and If I use getcomponent. It access only the 1st CircleCollider2D in the object.BUt I want access all 2 CircleCollider2Ds
You shouldn't add the same component to one object
But there is a function called getcomponents (with s) but I don,t know how to use it.