Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 eeveelution8 · Jun 15, 2013 at 01:23 AM · doorkeysimple

how do i do a simple key door

this is probably a frequently asked question, but i have used and tried 5 different scripts, all with the same result.

it not working.

if anyone knows a script please link it to me, because all i'm looking for, is a door that opens as soon as i touch a trigger.

i tried to make my own at one point:

 var door : Transform;
 
 function OnTriggerStay (other : Collider) {
 
     var contact : String = other.transform.name;
 
     if (contact == "Player"){
         
         
         Destroy(door);
         Destroy(other.gameObject);
 
         
 }
 }


its clear this doesn't work either :I

Comment
Add comment · Show 2
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 MrThreepwood · Jun 15, 2013 at 04:18 AM 0
Share

$$anonymous$$ake sure that you have rigid bodies on both of your objects (the trigger and the player) otherwise the game won't be able to detect a collision. I'm assu$$anonymous$$g your trigger isn't destroyed either? This script is attached to your player, right?

avatar image Ouija · Jun 15, 2013 at 10:37 AM 0
Share

pretty sure unity posted a tutorial about this on their website.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by iwaldrop · Jun 15, 2013 at 06:00 AM

First off, you probably don't want to try and destroy the same things every frame.

But as MrThreepwood suggested, you need to make sure that you have colliders on things. Your player should have a collider and rigidbody, where as you door should have at least a collider whose Is Trigger box is checked. Then do something like this:

 public GameObject door;
 private int count;
 
 void OnTriggerEnter(Collider other)
 {
     if (other.tag.Equals("Player"))
     {
         count++;
         door.SetActive(false);
     }
 }
 
 void OnTriggerExit(Collider other)
 {
     if (other.tag.Equals("Player") && --count < 1)
         door.SetActive(true);
 }

This will allow multiple players to enter the door collider area and will only close once all are out. Of course, for a single player game you can probably omit the counter.

Comment
Add comment · Show 1 · 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 eeveelution8 · Jun 16, 2013 at 02:09 AM 0
Share

I never thought of the rigidbodies, thanks

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make 2 doors with 2 diffrent keys 2 Answers

Pick up key and unlock a locked door 1 Answer

Scripting issue with opening a door with a key. 2 Answers

Locked door and key to open it script 1 Answer

Door Open With Object Pickup 1 Answer


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