How do I fill in a variable that isn't a component via script?

Hi
I know I can fill in a variable by using the getcomponent function (eg. MyCollider = getcomponent<.BoxCollider>() ; )

But how does it work if I want to fill in some info that is part of a component ? I’ll give an example of what I mean :

I have a script that has a Text Variable ( private Text newContact;)
First I wanted to do : newContact = getcomponent<.Text>() as text; But then I realized that Text isn’t a component , but just a piece of the script.

So since the script is a component, but Text isn’t… How do I fill in the right hand side of the Text Variable ?

To access from another script, you need to make newContact public, not private.

Then you access it with

GetComponent<Nameofscript>().newContact = newValue;

You get the script component, then set the variable field on that component…

newContact = GetComponent< YourScriptName >().Text;

Now, you’ve declared Text as a private variable so you won’t be able to access it like that. You can either make it public, or create a function to return the value.

private scriptObj SCRIPTNAME;

void Start(){
scriptObj = GetComponent<scriptObj>
}

then you can use the ‘scriptObj’ to access any public variable in the script/component;