public class ClassA : Class B
public bool varB;//how is this initialised?
public class ClassB : MonoBehaviour
public bool varA;
varA = true;
How is varB initialised?
Hi, You basically inherit a monobehaviour, so to initialize that variable, you can have following methods:
- You can attach ClassA to a gameobject in the scene. It will automatically initialized.
- You can directly call an object of ClassA and initialize the variable
( I guess you would have known this already )
However, there can be different scenarios:
When ClassA is attached to a GameObject and ClassB not:
The Start() of ClassB is called automatically as there is no override function in derived class. So, varA and varB, both will be initialized. (You can see both varA and varB in inspector and you can initialize from there also).
When ClassB is attached and classA is not:
The Start() of ClassB is called but no effect in ClassA so you need to call Object of ClassA in ClassB as:
a.varB = false;//Initialization
where ever you want. In order to call start of ClassA, you need to call it explicitly.
If no script is attached:
You can call the object of ClassA from other script and initialize it explictly.