- Home /
Key to use to unlock a teleporter
Hello
For my game I have several teleporters I want to have one of the teleporters locked until you collect a key which will enable the teleporter to be usable.
I have no idea where to start. At the moment the teleporters work. But what script would I need to add to the key and what would be needed to add to the teleporter?
Answer by karl_ · Apr 09, 2010 at 04:49 PM
Add a blocking bit of geometry in front of your teleporters, then when a key is collected disable the blocker.
In script, the destroy block would be something like this:
level_block = GameObject.Find("PortalBlock");
Destroy(level_block.gameObject);
Just add that after an If statement for determining key collection.
Key collection:
function OnControllerColliderHit(hit:ControllerColliderHit) { if(hit.gameObject.tag == "key") { Debug.Log("You picked up the key!"); Destroy(hit.gameObject); key++; // You should probably use a boolean here if you just have one key, but I've got this set to require a certain number of items to unlock.
}
}//END FUNCTION ONCONTROLLERCOLLIDERHIT
Ahh I see so I would need to create a box infront or around it so players cant go into it something like this:-
http://s48.photobucket.com/albums/f231/chillisguy/?action=view¤t=2.jpg
Also what script would I need to use to pick up said key
I've modified the answer to include our collection script. It's pretty much taken from Goldstone's book on Unity.
And yes, just create a simple plane or cube with collision turned on to block the player.
Hey thanks for that but it doesnt seem to work I added the script to a cube as a portal blocker but it just vansihes straight away, when I have is trigger on pr off.
What if statment would be best?
And what does key++ mean? The key works fine tho thanks :) I added it to my player and the key. Sorry for being a noob
Your answer
![](https://koobas.hobune.stream/wayback/20220612154350im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Door Open With Object Pickup 1 Answer
Unlocking Gate with Key 1 Answer
Help with making his work with a key 1 Answer
How to open a gate with a key ? 1 Answer
Problems with key script 0 Answers