- Home /
Stupid question about public / private variables
My issue is pretty simple: I've thrown together a rudimentary inventory system, where when EquipItem(InventoryItem) is called in my Inventory.js script, it modifies private variables in a script on the player called PlayerStatus.js.
I don't want the values for these variables accessible from the inspector (because they should be zero unless modified by an equipped item), but I can't modify private variables from another script.
Is there a way to have them be private, but accessible from another script?
This question is quite useful, but the title is not. The title should be something like "How can public variables be hidden from the inspector?"
Answer by Mike 3 · Jun 29, 2010 at 04:04 PM
Make the variables private, add functions to modify things
e.g.
private var armor;
function AddArmor(armorModifier : int) { armor += armorModifier; }
function RemoveArmor(armorModifier : int) { armor -= armorModifier; }
Both ideas here would work, the @HideInInspector thing is more what I was looking for though. Thanks! :)
@HideInINspector is fine but , $$anonymous$$ike 3 has, indeed, given you the most correct answer here. If seek the correct droid you do? R2D$$anonymous$$ike 3 is indeed the coupe(in respect to approach (i.e. hiding them confor$$anonymous$$g to an OO typey thingy)), and in context to your question of course. Though its fair to point out that what Eric5h5 says goes - Ive lost count how many times he`s helped me out of sticky code issues and Unity specific $$anonymous$$d grinders that only noobs like me come up against. :) :) Gruffy