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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by $$anonymous$$ · Aug 26, 2014 at 12:53 AM · javascriptontriggerenterloadlevelgetkeydown

Door script not loading the next scene?

Hello! I ask a LOT of questions here, but this one is confusing. :| This may also answer a different question too, but I made a script for a door using an OnTriggerEnter function and for some reason it refuses to work. Here is the script: #pragma strict

 var LevelNum : int;
 
 function OnTriggerEnter (PlayerCol : Collider)
 {
     if(PlayerCol.tag == "Player" && Input.GetKeyDown(KeyCode.E))
     {
         Application.LoadLevel(LevelNum);
     }
 }

This should work, but if the player goes to the door and presses E, it does nothing. I know I am doing the OnTriggerEnter right because I have other doors set up to display a GUIText to say that it is blocked or locked. Please help. This is confusing and makes no sense that it doesn't work. I may just restart the project to see if it is some problem with the assets or with the project itself. But, if there is just some simple error I missed then this will still be useful.

Comment
Add comment · Show 1
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 Turbine · Aug 26, 2014 at 02:27 AM 0
Share

You'd be getting an error in the console if it was failing to load the level, there's something else wrong if the console's empty.

1 Reply

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

Answer by Turbine · Aug 26, 2014 at 02:25 AM

You probably want to be using OnTriggerStay instead of OnTriggerEnter. OnTriggerStay is called every frame while you're inside the area. You should put some debug statements in your function to see where it's breaking. Make sure you have "IsTrigger" set on your collider. OnTriggerStay &Enter are both intended for 3D colliders, you'd have to use OnTriggerStay2D for 2D colliders.

Comment
Add comment · Show 2 · 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 $$anonymous$$ · Aug 27, 2014 at 03:16 PM 0
Share

Thanks a lot! I still have to test it, but I guess I still need to learn some new syntax. XD

avatar image $$anonymous$$ · Aug 27, 2014 at 04:41 PM 0
Share

Worked! Thanks a lot!

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

22 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

how can i load a scene when reaching certain score? Roll-a-Ball Project 1 Answer

my problem is a ontriggerenter new secene open,hello my problem is a 0 Answers

how can i make my character to be on another scene? 1 Answer

(Resolved) Load a Level by pressing a Key 1 Answer

When I go inside a collider I want GUI Text to appear, and allow me to press 'e' to swap scenes, but it instantly transports me to the scene. 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