C
C#3y ago
santijlm

Read and Set a variable from another script in unity

How can I edit a variable that is in another script linked to another object in unity?
4 Replies
Thinker
Thinker3y ago
Assuming you mean edit a property/field in another component, use var component = otherGameObject.GetComponent<TypeOfYourComponent>(); and then set whatever property/field you want using component.YourVariable = whatever;.
santijlm
santijlmOP3y ago
i mean a variable like a string but i think that could work
Thinker
Thinker3y ago
A "variable" is only something which can exist inside a method, outside a method it's called a field or a property.
santijlm
santijlmOP3y ago
oh, sorry then that's what i need
Want results from more Discord servers?
Add your server