I can’t get it to print “Updated” or anything when I hit F. I get no errors or anything, just nothing happens. I dont see anything wrong with the script. Whats up?
I believe the issue is that onEnter is called for one frame. It would be virtually impossible for your user to match this frame with pressing the key. Use onTriggerStay.
This might be awesome for tournament fighting game players who can hit a button with 1/60th of a second precision, but for the rest of us you’re asking too much. OnTriggerEnter only happens once, and GetButtonDown checks for a down event which happens for one frame.
You want to use OnTriggerStay, which fires once per frame while the triggers remain touching. That way you can take all the time you need.
As a bonus, if you only want the key to be used once per enter, stay, use a bool if true, key can be used. Use key, set to false. Allow it to switch back to true on exit or enter.
as I am working in the editor I am looking both at the amount of money the player has (which starts out as fifty) as well as what the upgrade station THINKS it has, which is also 50. On top of that if you look at the code I have it set to display the value of PlayerMoney.
I don’t think that is actually setting the amount of money to what you want it to be… That is the reason I told you to check
Also wherever Money is in the PlayerAttributes script how are you setting the value? in update? by default when you declare the variable? Its hard to tell what is going on without actually know how the value is being set in the first place.
Im not sure I understand you. If it is a value in the inspector than that is its value… It updates in realtime, right? The script above works fine because when I’m playing and I change the PlayerMoney variable in the inspector it reflects the changes on the GUI label and in the inspector of the upgrade station.
also I updated with camelCase. Thanks for letting me know about that.
Also, I can’t really remember exactly, but I’m not sure if that line would actually work as a pointer or if you should link to the PlayerAttributes component and then make the adjustment by calling playerAttributes.money -= upgradeCost instead. I’m probably too tired to be giving advice right now, but try that and see if it helps.