- Home /
How can I check the colliders of objects instantiated into the Scene
I have created a snake like enemy that instantiates segments on creation. I found that instantiating them into the "head" of the snake made them unable to properly follow the path of the head. Now though, I need their colliders to be checked for attacks and update the health of the "Head" script. I am unsure how to check their colliders and update the health of the specific enemy that created it.
Answer by JiveViking · Jul 07, 2020 at 06:00 PM
//instantiates the segments
for (int i = 0; i <= segs; i++)
{
segments[i] = Instantiate(body, transform.position, transform.rotation);
}
//this moves the segments
if(Vector2.Distance(segments[0].transform.position, transform.position) > 0.5f)
{
segments[0].transform.position = Vector2.MoveTowards(segments[0].transform.position, transform.position, bspeed * Time.deltaTime);
}
for(int i = 1; i <= segs; i++)
{
if(Vector2.Distance(segments[i].transform.position, segments[i - 1].transform.position) > 0.5f)
segments[i].transform.position = Vector2.MoveTowards(segments[i].transform.position, segments[i - 1].transform.position, bspeed * Time.deltaTime);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613002710im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiate 1 object after 2 objects collide. ( C# ) 1 Answer
Detect if colliding with nothing 0 Answers
How to detect child object collisions on parent 3 Answers
OnCollisionEnter not triggering when two rigidbody collide via Instantiate 1 Answer
Making the collider change after being instantiate 2 Answers