Script being used multiple times needing different variables but all are being overwritten when assigning variable in 1 instance of script

Hi. Very new to Unity. I’ve spent the last couple of days researching and getting nowhere with this. Hopefully someone here can help. I haven’t posted the code as the contents of the code are not important. I need help with referencing.

I am trying to make one of those incremental money games, but with a bit of a twist. The first section will be like having 3 games at the same time. In the code, I obviously have to reference the cost (text), amount (text), rate of income (text) and the button (button) for each minigame (for lack of a better term).

They all work identically. There are just 3 of them. However, when I assign the script to set 1, I assign (by drag and drop) the price, amount and rate, but it updates for all 3 instances of the script meaning set 1’s price text box is being used for all 3 minigames price. Which I do not want.

I am able to make the button work by assigning the script to the button and then using GetComponent(). However, I do not know the code required to do this for text boxes with the same parent or if I need to be assigning the script to the parent instead of the button or what I need to do.

I did have a way of making this all work by using a lot of code and it looked very messy, so worst comes to the worst, I have a way of fixing it. I just wanted to make the code a lot shorter, neater and simpler.

Show a minimal how to do a reproduction of the problem,

3 parents. All contain price, amount, rate and a button. Assign script to all of the buttons. Button is then assigned using the GetComponent function in the code (assigning the button works as intended. I’ve checked it).

The problem comes when trying to assign the other textboxes. Once I drag and drop to assign one of the price texts to the script on the button with the same parent, it assigns it to all 3 instances of the script. I want each of the scripts to have a different price textbox associated with it.

thats not showing how to reproduce it… while thats nice instructions, whats the relevant bits of script and fields and so on behind it…

The script is currently empty. All I’m trying to do so far is assign text boxes to the correct TextMeshProUGUI’s in my script. The script currently does nothing and contains nothing other than naming public variables as I can’t get it all assigned properly.

Resolved. Turned Unity off and on again. Works fine now. No better solution than this. Sorry.