- Home /
Referencing variables via external script?
I want to reference variables from script A into script B.
I'm using GetComponent and everything works fine.
The only issue I'm running into is that I have about 100+ variables in script A, and I don't want to declare each and every one of them as 'public' so that they can be used in script B.
Is there a way so that script B can be allowed access to all variables from script A including non public members?
Answer by haim96 · Dec 09, 2013 at 02:10 PM
maybe using properties can help somehow. watch this video: http://unity3d.com/learn/tutorials/modules/intermediate/scripting/properties
That's pretty neat, and is probably what I'll have to do. Just leaving this question open for a bit to see if there's an even easier way (as I'll have to get/set 100 variables using your method) otherwise this one will be accepted
to make sure you fully understand, ins$$anonymous$$d of declare 5 vars for player attributes you declare "Player" class with 5 properties. then you need to create one var of "Player" type and you can set or get his properties values. you can also pass over all properties to new var from the same type if you need. the new var will have all the properties values... good use for this is for Player, Products, inventory etc...