Chciałabym bym sie odwołać do wartości "CarriedWateringCan" która znajduje sie w skrypcie "Player" ale ilekroć pisze tak wyskakuje mi bład "NullReferenceException: Object reference not set to an instance of an object FirstSlot.Update () ". Dodam rownież że jak wpisuje Debug.Log z tą wartoscią w skrypcie "Player " to normalnie pokazuje mi to swoją prawidłową wartość. W jaki sposób mam wiec zobaczyć tą samą wartość gdy odwołam sie do niej ze skryptu "FirstSlot"?.
Skrypt "Player":
public class Player : MonoBehaviour {
public WateringCan CarriedWateringCan;
Skrypt w kórym chce sie odwołać do tej wartosci "FirstSlot":
public class FirstSlot : MonoBehaviour {
public GameObject Inventory1;
public Transform canvas;
public static bool oneicon = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Player ObjectPlayer = GetComponent<Player>();
if (ObjectPlayer.CarriedWateringCan != null && oneicon == true) {
GameObject inventory = Instantiate(Inventory1, canvas);
oneicon = false;
}
}
}