Yep, it’s got a grappling hook!
I have something in particular I want to do with grappling hooks that I’m not ready to talk about yet. But grappling hooking around is also part of a set of interactions that I hope are going to just feel really nice – to some extent this game would be about the pleasure of execution.
This is just a quick demo of how it’s working right now – shoddily, but well enough to give me an idea of how to refine it. I’m pretty pleased to have got this far in three days, despite still really struggling with some Unity stuff.
A question for experienced Unity users:
I’m having trouble understanding how I’m meant to make different components talk to each other.
I have one component that handles the ‘fire a grappling hook’ code.
In that component, I use a boolean variable called grappleAttached to keep track of whether we’re currently grappling.
Other components regularly need to know this information too.
The component that handles walking left and right, for example, needs to make those controls behave differently if we’re grappled onto something.
This is going to come up a lot – almost everything you can do will depend on whether you’re grappled or not.
The only way I know of having any other components access this variable is with GetComponent.
This seems to require three different lines of code: one variable declaration, one in Start to store the component as a variable, and then another wherever I want to check grappleAttached.
Is that really the best way to do it? It seems like a lot of mess, and a lot to change if I ever move that piece of code or rename the component (which seems to be difficult, but commonly necessary as I experiment with what each component should do). I’ve also been warned that GetComponent is slow.
Similarly, I’ve written a function to get the position of the cursor. Do I have to do this whole process in every script on every object that ever needs that information?
Thanks for any advice.