Hello,
I’ve searched the forums and answers on this, and have perhaps improved my code but it still doesn’t work – I get "‘player1’ is not a member of ‘gameController’. " as an error on the following scripting. Any idea what I’m doing wrong? I’m guessing the error is in the player script.
gameController.js
class PlayerData{
public var mightBase;
public var mightBonus;
}
var player1 : PlayerData = PlayerData();
player1.mightBase = PlayerPrefs.GetInt(gameNumber + "_1_might_base");
player1.mightBonus = PlayerPrefs.GetInt(gameNumber + "_1_might_bonus");
playerScript.js
playerMight = gameControllerObject.GetComponent(gameController).player1.mightBase + gameControllerObject.GetComponent(gameController).player1.mightBonus;
The name in GetComponent has to be exactly the same as the file name, aka if the file name is Game Controller, the get component has to be "Game Controller" Just as a standard naming convention, name it GameController, not gameController and no space :)
– Benproductions1Oh, they are correct. I'm modifying my code from using individual variables to using the class -- first time using the class. That's why I'm pretty sure the problem is in the player script part, specifically the "player1.mightBase". Usually I'd just have a var player1MightBase so calling .player1MightBase would work (And did), but I'm not sure how to get access to the class variable. gameControllerObject.GetComponent(gameController).player1.mightBase
– infinitypbr