Hey, Im making a game where you can acess a store. The store works perfectly until I add another store in the scene. Whenever I click buy on the second created store, the gameobject instantiates in the first store’s spawn point. This doesnt make sense to me since the second store has its own spawn point, far away from the first store’s spawn point, however using the same script. Take a look at my script:
public class Store : MonoBehaviour
{
public GameObject killCount;
KillCount theCount;
public int[] prices;
void Start()
{
theCount = killCount.GetComponent<KillCount>();
StoreUI.gameObject.SetActive(false);
//Setting up prices
prices[0] = 250;
prices[1] = 300;
prices[2] = 400;
prices[3] = 500;
prices[4] = 600;
prices[5] = 600;
prices[6] = 750;
prices[7] = 750;
prices[8] = 750;
prices[9] = 750;
prices[10] = 750;
prices[11] = 750;
prices[12] = 850;
prices[13] = 1000;
}
public void GivePistol()
{
if (theCount.currentKillCount >= prices[0])
{
Instantiate(weapons[0].transform, spawnPoint.transform.position, Quaternion.identity);
UnsufficientFunds.gameObject.SetActive(false);
}
else
{
UnsufficientFunds.gameObject.SetActive(true);
}
}
public void GivePistolDW()
{
if (theCount.currentKillCount >= prices[1])
{
Instantiate(weapons[1].transform, spawnPoint.transform.position, Quaternion.identity);
UnsufficientFunds.gameObject.SetActive(false);
}
else
{
UnsufficientFunds.gameObject.SetActive(true);
}
}
}
On the Script KillCount I wrote this:
public class KillCount : MonoBehaviour
{public int currentKillCount = 10000;
public GameObject Store;
Store theStore;
public void BuyPisltol()
{
currentKillCount -= theStore.prices[0];
text.text = TEXT_PREPEND + currentKillCount.ToString();
}
public void GivePistolDW()
{
if (currentKillCount > theStore.prices[1])
{
currentKillCount -= theStore.prices[1];
text.text = TEXT_PREPEND + currentKillCount.ToString();
}
else
{
Debug.Log("Unsufficient funds");
}
}
}