How to access a class from one script in another when they are both attached othe same object?

Say I have a script x attached to a cube. It contains a class and all its functions, etc.
Now there is another script which is on the same cube and has to call functions like x.DoSomething(); How do I access the entire class from another script when it is on the same gameObject?

Heres a example from a script I wrote.

private PlayerVitals Pv;//Gets Ref For My Player Vitals Script

Pv = GameObject.GetComponent<PlayerVitals>();//in Start method

it’s in c# but should be able too help you.
Also check out the Learn section for their example on how too get a Component script if this doesn’t help.

GetComponent is easiest if you know what class you are after


SendMessage works well if you don’t know what class you are after. I use SendMessage mainly for events that several classes might be interested in. (e.g. “Die”, “Damage”, “Selected”)


To get components on a different GameObject simply add a reference to the GameObject instead of gameObject