this is my first post here. I'm doing pong game in Unity, and i have problem finding instantinated gameobject ball, which i want to gets it's position to program AI controlling second Paddle. Here how it looks like:

GameController.cs:

```
public class GameController : MonoBehaviour
{
public GameObject ballPrefab;

public Text score1Text;
public Text score2Text;
public float scoreCoordinates = 3.4f;

private Ball2 currentBall;
private int score1 = 0;
private int score2 = 0;

// Start is called before the first frame update
void Start()
{
    SpawnBall();
}

void SpawnBall()
{
    GameObject ballInstance = Instantiate(ballPrefab, transform);
    currentBall = ballInstance.GetComponent<Ball2>();
    currentBall.transform.position = Vector3.zero;
    score1Text.text = score1.ToString();
    score2Text.text = score2.ToString();
}

// Update is called once per frame
void Update()
{
    if (currentBall != null)
    {
        if (currentBall.transform.position.x > scoreCoordinates)
        {
            score1++;
            Destroy(currentBall.gameObject);
            SpawnBall();
        }

        if (currentBall.transform.position.x < -scoreCoordinates)
        {
            score2++;
            Destroy(currentBall.gameObject);
            SpawnBall();
        }
    }
}
}

```

AI.cs:

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AI : MonoBehaviour
{
private Rigidbody2D AIrig;
private Ball2 ball;
public float speed = 1f;

// Start is called before the first frame update
void Start()
{

    ball = GetComponent<Ball2>();
    AIrig = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
    ball.transform.position = Vector3.zero;
    if (ball.transform.position.y > AIrig.transform.position.y)
    {
        AIrig.velocity = new Vector2(0, speed);
    }
    else if (ball.transform.position.y > AIrig.transform.position.y)
    {
        AIrig.velocity = new Vector2(0, -speed);
    }
}
}

```

Ball2.cs:

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ball2 : MonoBehaviour
{
public float minXspeed = 0.8f;
public float maxXspeed = 1.2f;

public float minYspeed = 0.8f;
public float maxYspeed = 1.2f;

private Rigidbody2D ballRigidbody;

// Start is called before the first frame update
void Start()
{
    ballRigidbody = GetComponent<Rigidbody2D>();
    ballRigidbody.velocity = new Vector2(Random.Range(minXspeed, maxXspeed) * (Random.value > 0.5f ? -1 : 1), Random.Range(minYspeed, maxYspeed) * (Random.value > 0.5f ? -1 : 1));
}

// Update is called once per frame
void Update()
{

}

private void OnTriggerEnter2D(Collider2D otherCollider)
{
    if (otherCollider.tag == "Limit")
    {
        if (otherCollider.transform.position.y > transform.position.y && ballRigidbody.velocity.y > 0)
        {
            ballRigidbody.velocity = new Vector2(ballRigidbody.velocity.x, -ballRigidbody.velocity.y);
        }
        if (otherCollider.transform.position.y < transform.position.y && ballRigidbody.velocity.y < 0)
        {
            ballRigidbody.velocity = new Vector2(ballRigidbody.velocity.x, -ballRigidbody.velocity.y);
        }
    }
    else if (otherCollider.tag == "Paddle")

    {
        if (otherCollider.transform.position.x < transform.position.x && ballRigidbody.velocity.x < 0)
        {
            ballRigidbody.velocity = new Vector2(-ballRigidbody.velocity.x, ballRigidbody.velocity.y);
        }

        if (otherCollider.transform.position.x > transform.position.x && ballRigidbody.velocity.x > 0)
        {
            ballRigidbody.velocity = new Vector2(-ballRigidbody.velocity.x, ballRigidbody.velocity.y);
        }
    }
    }
}

```

I can't get refference to instantinated object (ball). If anyone could help me i will be grateful.