Setting a game object in another script

ok guys I am following a tower defense tutorial and want to made some changes
there is a method which place a prefab on a tile and disable the tile

        if (creditCount >= costValue[turretIndex])
        {
            creditCount -= costValue[turretIndex];
            Instantiate(turretPrefabs[turretIndex], tile.transform.position, Quaternion.identity);
            tile.SetActive(false);
            canBuild = false;
            aud.PlayOneShot(turretDrop);
        }

Now I want to add this disabled tile to a game object in another script so i can eanble it again later
so I added this line

turretPrefabs[turretIndex].GetComponent<SellItem>().tile = tile;

but it assign random tile to it and not one i want

please help

Good day.

It does not assigna random tile. If a tile is assigned to variable “tile”, is because you did it. If do that new code at the same method, where your variable “tile” have assigned the tile you want, it will act over that tile. if you are doing this in another script, you should know what tile is assigned to variable “tile”…

Bye.

@tormentoarmagedoom
I added second line of code to the first one like this

if (creditCount >= costValue[turretIndex]) { creditCount -= costValue[turretIndex]; Instantiate(turretPrefabs[turretIndex], tile.transform.position, Quaternion.identity); print(turretPrefabs[turretIndex]); print(turretPrefabs[turretIndex].GetComponent<SellItem>().tile); tile.SetActive(false); turretPrefabs[turretIndex].GetComponent<SellItem>().tile = tile; canBuild = false; aud.PlayOneShot(turretDrop); }

there is another scripts “SellItem” which holds a variable “tile” . and i want to assign a game object to it