Accessing Normal Class from another class which derives from Monobehaviour

Hi,

I Created an Normal .CS Script for getting the instance
whenever i called the particular function in following script.

public class Indexer
{
    private static Indexer instance = null;
    
    public static Indexer GetInstance()
    {
          if(instance == null)
	  {
		instance = new Indexer();	
	  }
	  return instance;
    }
}

Trying to call GetInstance() in to the Class which derives Monobehaviour like below:

private Indexer index;
public class Model : Monobehaviour
{
    void Start ()
    {
	index = Indexer.GetInstance ();
    }
}

I am doing this process when user swithces from one scene to antoher scene.(say, Menu to Game scene).

But, because of this line [index = Indexer.GetInstance ();]
it hangs and crahses unity many times.

Can anyone help to solve this issue. . ?

The posted code seems in order. It must be something in the constructor of your Indexer that crashes Unity.

Also, making the Indexer a sole public class in your Normal.cs file could help.

That code has a few errors and would not compile.

1: You can not have global variables in C#, the line “private Indexer index;” needs to be inside the Model class.

2: MonoBehaviour is written with an upper case B.

It should work after that though.