OK, I was up half the night trying to get this to work. I figure OK first lets see if I can just get it to work without the key as I've never tried doing an open opperation of this type before.
So what I have is when you approach the gate and press the action key, in this case "Q" the gate's state will change from "Locked" to unlocked and it plays the animation with the lock openning and then placing itself ontop of the gate, I was originally just going to have the lock drop to the ground, eh, whatever works though ;)
next by pressing the action key again the gate will now swing open... Mmmmm lovely, brimming over with deliciosness actually.
Now I know there was another poor bastard like me on here having the same issue so if yur out there buddy and still looking for a fix here is my script, you might need to mod it a bit but it works for unlocking at a key input press:
Now to all you code brainiacs out there lol How can I get this to function after my FPS player has picked up a key?
now that should be straight forward enough!! Sorry if I seem a little "Shnarky" but lack of sleep will do that to a fella ;)
EDIT This is my Key pickup script which is attached naturally to the Key that is a pickup object just incase for some reason you need to see that:
EDIT #2 I uploaded a video clip to my YouTube Channel just incase you would like to see what I'm trying to do. As you can see when you approach the gate and are close enough, press "Q" and Unlock the Gate, Press "Q" again and the gate swings open. Now all I need is to get that to work with the key pick up and life will be peachy ;)
EDIT # 3 THE SOLUTION!!!
OK Mr. Dave below is correct. here is what I did I added a new variable at the top of my Player script:
And then tweaked this part of my Player script:
And in the Inspector dragged my "Key Game Object" (Pickupable) onto the variable setup in the inspector...
Now I'm not sure if that is what one is supposed to do... but it works... The gate will not unlock unless you have picked up the key, then you can unlock and then open the gate. Sweeeeetness :) And then the pesants rejoyced ;)
I assume you have a 'player has key' var around somewhere, right? If it were on a 'Player' component, where player :Player
Which seems too simple to be what you're looking for, so maybe I missed the point?
answered Apr 14 '11 at 08:30 PM