Quantcast
Channel: Questions in topic: "class instance"
Viewing all articles
Browse latest Browse all 131

singleton pointer and updating variables of the singleton with the pointer

$
0
0
When i have created a player class and created a singleton in it: public static Player instance; void Awake() { if (instance != null) { Debug.LogWarning("More than one instance of Inventory found"); return; } instance = this; } one variable in Player class is playerData and in player data where is a variabale inventory (array of items). in the inventoryUpdate scrip i want to change the items in the inventory that is in the player class . I don't want to call the class every time i want to change (not to call Player.playerData.inventory every time) I tried to point on the inventory variable and call it on Create local variable inventory and that will point on inventory in Start(){inventory = Player.playerData.inventory;} but the playerData.inventoryin in the player class is not changing when i try to change it on the inventoryUpdate with the local pointer inventory: inentory[0] = newItem("sword") and it is changing only the local pointer and not the original variable. I thought that if i never defined a new instance (never used new word) it is only a pointer and it will change the original variable. is there any way to do it? defined a pointer correctly?

Viewing all articles
Browse latest Browse all 131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>