I am new to game development, currently working on a tower defence game.
I have encountered an issue where both Upgrade 1 & Upgrade 2 buttons are working as intended. However, after adding a 3rd and 4th Upgrade button, they call on the Upgrade2() method instead of the Upgrade3() and Upgrade4() methods respectably even after I changed their on click event. (Buttons 1 & 2 work fine, it’s just 3 & 4 that call on upgrade 2’s method)
I have tried everything to sort the issue but I cannot find a solution and I would appreciate some help if possible. (There is two images attached of Upgrade2() and Upgrade3() for examples to show they are the same except for their prefab)
If the code is the same except for the prefab and you’re sure that the onClick event of the button is calling the correct method, then the problem would have to be with your prefab assignment. If you have public references to them in the inspector, double check that prefab2 isn’t in the prefab3 and prefab4 slots.
Also, it’s helpful with things like this to use the built in debug methods to help spot your issue. You could add something like Debug.Log(“Upgrade 3 called”); to the top of your UpgradeTurret3() and see if that comes up in the console when the button is clicked. Similarly you could add such a line to each of the upgrade methods to see which is being called when you click, just to confirm everything is working as it should. If those are called correctly, it’s an issue with the prefabs, if they aren’t and the inspector says you have the right methods selected for your buttons, it might just be that Unity needs a restart.