Storing collided gameObject array index

Hi Everyone,

I have 3 gameObject players in array.

public GameObject [] player;
player = GameObject.FindGameObjectsWithTag ("PlayerBlue");

if (collision.gameObject.tag == "PlayerBlue")
{
    i = (store array index here)
    transform.parent = player*.transform;*

}
How do I store the index of collided game object? I want to make collided player to be the parent of the ball.
Please advise.
Thank you.

You could do it like this:

if (collision.gameObject.tag == "PlayerBlue")
{
	for (int j = 0; j < player.Length; j++) {
		if (player[j] == collision.gameObject) {
			i = j;
			transform.parent = player*.transform;*

break;

  •  }*
    
  • }*
    }
    We compare the tagged game objects with the collision game object and save it if it’s the right one.