Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GeneralGadd · Apr 09, 2010 at 04:27 PM · keyunlock

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GeneralGadd · Apr 09, 2010 at 05:55 PM 0
Share

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

avatar image GeneralGadd · Apr 09, 2010 at 05:59 PM 0
Share

Also what script would I need to use to pick up said key

avatar image karl_ · Apr 09, 2010 at 06:57 PM 0
Share

I've modified the answer to include our collection script. It's pretty much taken from Goldstone's book on Unity.

avatar image karl_ · Apr 09, 2010 at 07:00 PM 0
Share

And yes, just create a simple plane or cube with collision turned on to block the player.

avatar image GeneralGadd · Apr 09, 2010 at 08:28 PM 0
Share

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

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges