Calling a method from a parent object's script using the child's script

,

Hello guys!

I’ve got a ParentObject with a script called MainScript, and in the script, a method called printToConsole(). I want to access the printToConsole method from a script in the child object.

In the child object script, I’m writing the following:

MainScript ParentScript;

private void HandleSelected()
{
ParentScript = transform.parent.GetComponent();
ParentScript.printToConsole();
}

This gives me the following error:
error CS0246: The type or namespace name ‘MainScript’ could not be found (are you missing a using directive or an assembly reference?)

I’m new to Unity Development and would really appreciate some help. This seems to be an easy fix, but it just hasn’t worked for me and I’ve tried really hard for days to make this work.

I don’t know why the namespace is giving me that error. I added a test box collider to the parent class, and with that exact same line of code, I’m able to disable the boxcollider component. If I try to disable the script (MainScript) component, it says the namespace name ‘MainScript’ cannot be found. I dont understand why this would happen. The script, just like the boxcollider, is a component in the parent object. The child can perfectly access the box collider component but not the script… why?