So I am making a TD game as the title says. I have created a very simple currency system and I am trying to subtract it from where the tower is instantiated. However this isn’t working, and sometimes it breaks the whole instantiating process, and only lets me place one of each kind of turret. Here is the code where the turrets get placed:
`public void OnEndDrag(PointerEventData eventData)
{
if (prefabInstance.activeSelf)
{
Instantiate(prefab, prefabInstance.transform.position, Quaternion.identity);
}
prefabInstance.SetActive(false);
I have tried adding this in multiple places to get it to subtract scrap(the currency) and it isn’t working.
if (scrap.scrap < cost)
{
return;
}
else
{
scrap.SubtractScrap(cost);
}
}
If anyone has any suggestions on how to fix this or go about it, I would greatly appreciate it!