Hello, I put in my project to Xcode but, of course I have some how 278 errors when it builds onto my phone.
I need some help on this one and only problem I have on my scripting. It says
NullReferenceException: Object reference not set to an instance of an object
ShopItems.Update () (at Assets/Scripts/ShopItems.cs:29)
Using C#
I have the script right here. If you can help with the problem it would be great.
usingUnityEngine;
usingSystem.Collections;
usingUnityEngine.UI;
publicclassShopItems : MonoBehaviour {
publicTextItemNameText;
//publicTextItemCostText;
publicTextItemNOPurchasesText;
publicstringItemName;
publicintNOP;
publicintItemCost;
publicintDimondsCost;
publicintGoldCost;
publicintIronCost;
publicintMoneyAvalible;
publicintLevels;
publicintScoreTypeAuto;
publicintScoreTypeClick;
publicintAddLevelCost;
voidStart () {
ItemNameText.text = "" + ItemName;
//ItemNOPurchasesText.text = "" + NOP;
//MoneyAvalible = PlayerPrefs.GetInt ("DepthLevel");
}
voidUpdate () {
MoneyAvalible = PlayerPrefs.GetInt ("Depth Level");
ItemNOPurchasesText.text = "" + NOP;
}
publicvoidItemBuyClicked(){
if (ItemCost <= MoneyAvalible) {
MoneyAvalible -= ItemCost;
Levels = MoneyAvalible;
PlayerPrefs.SetInt ("Depth Level", + Levels);
NOP += 1;
ItemCost *= AddLevelCost;
} else {
Debug.Log("DidntHaveEnough");
}
}
}
First of all next time try do format your code a litle bit 
Second can you tell us in which line of code this null ref is, your error says Line 29 but i don’t think it matches with the code you posted.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ShopItems : MonoBehaviour {
public Text ItemNameText;
//public Text ItemCostText;
public Text ItemNOPurchasesText;
public string ItemName;
public int NOP;
public int ItemCost;
public int DimondsCost;
public int GoldCost;
public int IronCost;
public int MoneyAvalible;
public int Levels;
public int ScoreTypeAuto;
public int ScoreTypeClick;
public int AddLevelCost;
void Start () {
ItemNameText.text = "" + ItemName;
//ItemNOPurchasesText.text = "" + NOP;
//MoneyAvalible = PlayerPrefs.GetInt ("DepthLevel");
}
void Update () {
MoneyAvalible = PlayerPrefs.GetInt ("Depth Level");
ItemNOPurchasesText.text = "" + NOP;
}
public void ItemBuyClicked () {
if (ItemCost <= MoneyAvalible) {
MoneyAvalible -= ItemCost;
Levels = MoneyAvalible;
PlayerPrefs.SetInt ("Depth Level", + Levels);
NOP += 1;
ItemCost *= AddLevelCost;
} else {
Debug.Log("DidntHaveEnough");
}
}
}
Ok, I thought I do pretty clean code. But line 29 seems to be the problem. I get Depth Level and ItemName.
I don’t have anything thats not used. All 95 Items have Name. I think NOP (Number of purchases) is the problem. I changed the int to make it equal 0. It doesn’t show the error any more. Thanks for the help though.