The code snippet below is on a script attached to a GameObject in the Canvas that has a Button on it. It populates that Button’s OnClick listener. The code is executed when the button is clicked. The problem is the final line of code never executes. The GameObject is never turned off. The IF statement that encapsulates that line does indeed return true (as I’ve tested it thoroughly through debugging). The method “TransferEnhancementToUnit” returns a boolean value obviously. Any ideas on why the GameObject can’t be turned off?
public void OnClick()
{
if (Game.instance.selectedUnit != null)
{
if (Game.instance.localPlayer.TransferEnhancementToUnit(Game.instance.localPlayer.Enhancements[enhancementIndex], Game.instance.selectedUnit))
gameObject.SetActive(false);
}
}