- Home /
Upgrade Button 3 & 4 calling on the Upgrade 2 method
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)
This is where the buttons are in the hierarchy with what the OnClick() looks like for an example. Sorry if this was not what you were asking to see, I'm new at this and I think this is what you requested. I can always send more screenshots, I appreciate the help.
Yeah, that's pretty much it. Now show me the OnClick() for the buttons for Upgrade 3 and Upgrade 4
Can you show the turrentBlueprint in the inspector, as much of it as possible...
The turret blueprint is just what holds all the prefabs and costs for the main turret and its upgrades. I've set them to their correct prefabs in the shop as you can see in the second image but whenever the 3rd or 4th button is pressed it will result in the console saying its the upgrade 2 method even though I've set them to call the 3rd and 4th method
May I see prefabs 2 and 3? if you don't $$anonymous$$d posting it
Answer by Chimer0s · Jan 16 at 04:51 AM
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.
Hi, thanks for your answer. I did actually implement a debug.log statement into the Upgrade methods and whenever I pressed the 3rd or 4th button it would put "Upgrade 2" in the console. Thats why I was so confused whilst investigating it as I couldn't actually find a source of the error because the onclick events say they should call the right methods but they don't. But on the topic of a Unity restart, I have restarted Unity but do you think this issue could be caused by Unity not being updated to the latest update?