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
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;
.i mean a variable like a string
but i think that could work
A "variable" is only something which can exist inside a method, outside a method it's called a field or a property.
oh, sorry
then that's what i need