I am trying to create code for a student where the player finds a colored key and once they find the key, the key disappears and is ‘handed’ to the nearby guard. The code I have works IF the player clicks on the closest guard. If they click on the wrong guard, the wrong key appears. I am hoping for code that has specific keys linked to specific guards. Help!
Hi @TechWarriors, I made this work by remembering the last key clicked in the scene and adding a placeholder object for the key (with the desired rotation and placement) to the guard’s hands, in this case just an invisible cube.
From there I made a function where you can assign a guard a “correct key”, then when they are clicked (and the player has clicked a key before), give the guard a copy of this key; If the key == correct key, tell them thank you, Else tell them it is the wrong key, and make that key visible again, and re-assign it’s on click event;
Hope to have helped, and as always if you have questions feel free to ask!
Thank you so much Luc!
1 Like