- Home /
Only some methods seem to be accessible
Hi I am simply trying to access a method from another script. I have a script named BankScript which contains 2 public methods named respectively: public void buyItem(int moneyCost, int energyCost) and public void addEnergy(int energyDeposit). Another script is trying to access these methods.
I successfully referenced a BankScript object in my other script as it is actually able to access the buyItem method ( it gets listed in the list of methods I can use). I also have a button on another GameObject from this scene that is linked to this buyItem method and it works fine.
But curiously, I coded the AddEnergy method in BankScript and I do not see it appear in the list of available methods when I try to access it from the other Script...
Both methods are public and very similar. Do I need to do something particular to have my methods accessible from other scripts?
Similarly, I noticed the same for public variables in my BankScript, some are accessible and some are not? Even though they were all declared public...
I am clearly missing something but my limited programming knowledge does not allow me to figure it out.
Thank you all for the help.
at the very least, you need to post your scripts if you are requesting help. your description isn't complete enough for anybody to provide a meaningful answer.
please make sure that all code if formatted (highlight the code and click the 101/010 button above the edit box).
I'm terribly sorry for not posting code as I assumed it was either a mistake from my end or a very obvious step I was unaware of.
Indeed, I had somehow 2 scripts with the same name opened in my editor. I was editing the incorrect one.
Sorry for wasting your time. I will add code if I have questions from now on. Thanks.