Z
Z
Zimaell2021-03-21 14:02:32
C++ / C#
Zimaell, 2021-03-21 14:02:32

How to use one method in another class?

The solution to this issue has now become incomprehensible to me - since it works in one place, but not in another, here is an example, the class itself

public class DataStorage : MonoBehaviour{
    public Text ScoreText;
    public static DataStorage instance;
    void Awake(){
        instance = this;
        }
....................................

this is how i apply it in one in class

public class CanvasBoard : MonoBehaviour{
  private DataStorage Di;
  public static CanvasBoard instance;
  private void Awake(){
    instance = this;
    Di = DataStorage.instance;
    }
...........
  void Update(){
    Di.ScoreText.text = "" + Score;
.........

but I'm already using it in another class, but for some reason it doesn't work there the same way

public class IAPSeller : MonoBehaviour, IStoreListener{
  private DataStorage Di;
  public static IAPSeller instance;
    private void Awake(){
        instance = this;
        Di = DataStorage.instance;
...........
    private void InitializationLot(Product p){
       Di.ScoreText.text = "11111";
.........

and here this does not work anymore, although the application scheme is the same ....
What could be the matter?

the error where applied is something like this
NullReferenceException: Object reference not set to an instance of an object
IAPSeller.InitializationLot (UnityEngine.Purchasing.Product p) (at Assets/Resources/Scripts/IAPSeller.cs:632)
............. ...............

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-03-21
@Zimaell

The sequence of wakeup calls is a vague and indefinite matter.
Do you guarantee that DataStorage class Awake will be called before IAPSeller?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question