Hello all, I'm very new to the community, but I have had a couple of these errors come up and I know what they mean and have been able to fix them. To my current knowledge, it means that the program can't find an instance within the code and I probably have messed something up. However, this current piece of code seems to not be working very well.
public void BuyObject(string Name, int Price)
{
int Money = PlayerStats.Money;
if (Money >= Price)
{
PlayerStats player = gameObject.AddComponent();
player.PayFor(Price);
PlayerPrefs.SetString(Name, Name);
Transform Item = ShopScroller.Find(Name);
TextMeshProUGUI ItemPrice = Item.gameObject.transform.Find("Buy").Find("Price").GetComponent();
Transform BuyB = Item.gameObject.transform.Find("Buy");
ItemPrice.gameObject.transform.parent = Item.gameObject.transform;
ItemPrice.text = "Owned";
Destroy(BuyB);
}
}
This is a function I created to handle a purchase. It takes a name and price and goes through all the motions as you can see by the functions within it. The error falls onto **line 87**, it appears that my ShopScroller variable (which is a transform linked to a **"Content"** child of a ScrollView UI) is not being recognized even after I can clearly see in the Inspector of my Shop that it is.
![alt text][1]
[1]: /storage/temp/185551-newsc.png
All of the Children of **Content** are created when the shop opens, but the functions that run when I buy these are called on a button press after the shop is opened, so the problem cannot be that it is called too early.
Each one of the items in the photo consists of an empty object called **"ShopSection(Clone)"** which is just a clone I'm using to copy what each object looks like in the shop. However, the problem is occurring on line 87 so this is not the case, because the error is before we get that far.
I know this is a very long question but I am really in need of help on this one. Please feel free to ask any clarifying questions needed.
↧