Calling a method of a class that is a part of another class?

Hello Devs,

Lets say I have a file called as LevelManager.cs and it looks like this

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
 
public class LevelManager : MonoBehaviour
{
        // code
}
 
public class LevelInformation
{
        static float LowestPoint, HighestPoint, HeightOfTheTree;
        static int CurrentLevelNumber;
               
        public static int GetCurrentLevelNumber ()
        {
                return CurrentLevelNumber;
        }
}

Now outside of this file, can I call a method like this →

Debug.Log(LevelInformation.GetCurrentLevelNumber ());

I am under that assumption that as

  1. It does not inherit monobehaviour
  2. It is a public class and a public method
  3. The variable is a static variable

I can call this directly. Basically I am trying to call its method.

Please do correct if I am wrong.

You help is much appreciated.

Thank you,

Karsnen.

A static method cannot require a reference to another variable outside of itself. (Unless you grab the variable within the method, like using GameObject.Find(“name”).GetComponent<>)

I believe if you just make the class itself static, then you can access the level number like so:
int number = LevelInformation.CurrentLevelNumber. But you can only have one ‘copy’ of that class. (Singelton)

Making the class static:

public static class LevelInformation

You could then most likely remove the static keywords from within the class.