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 Paragram · Mar 28, 2016 at 12:33 AM · scene-loadingscene-switchinginteraction

how do u load a scene when pressing e on a object in game?

hello guys i have a small problem here that i thought u guys might know an answer too ;D, i have a problem with unity, i want to be able to load a scene when i press e on a object. i already did this on a button in the main menu using this code: public void LoadSceneMode(string name){ SceneManager.LoadScene(name); } public void QuitGame(){ Application.Quit ();

but that was a button and not a object in my game i have tried to change the code using Input.GetKeyDown(keyCode.E) but it just wont work does anybody of u guys know how to make this work? again i am not trying to change anything in the game just trying to open another scene


i am not a very experienced coder just doing it for fun ;D

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aditya · Mar 28, 2016 at 12:09 PM

try this using unityEngine; using unityEngine.SceneManagement; using System.Collections;

 public class loadScene : Monobehaviour{
         void Update(){
                 if(Input.GetKeyDown(KeyCode.E))
                         SceneManager.loadScene(`SCENE NAME`);
         }
 }
Comment
Add comment · 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
0

Answer by Aelrift · Jun 10, 2017 at 10:41 AM

First of all , does your object have a rigidbody and a collider with trigger enabled? That might be why it doesn't work.You also used Input.GetKeyDown, which returns true fonly for the one frame you start pressing it. You should use Input.GetKey instead I have done the same thing in my work, here's is how I did it : public void OnCollisionEnter2D(Collision2D collision)

     if (Input.GetKey(KeyCode.E) == true)
     {
         SceneManager.LoadScene("Realms of Eyre", LoadSceneMode.Single);
     }



 Where you would replace Realms of Eyre by the scene you want to load. Be sure to include using UnityEngine.SceneManagement at the very beginning of your code

Comment
Add comment · 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
0

Answer by FunIsDangerous · Jun 12, 2017 at 08:59 AM

Go to build settings, and press "Add Open Scenes" so that you see all your scenes there. The previous answers should explain the rest. Also, if by "when pressing e on a object" you mean looking on the object and pressing E, then you need to fire a Raycast towards where you are looking until it finds an object. If it does, and the object is the one you want (for example, a button), change the scene. You can also either get the object's position and calculate how far it is, or just limit how far the raycast will go

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Predfined Level Generation Procedural vs Scene 1 Answer

Help with loading scenes 2 Answers

Using parameters of activeSceneChanged? 0 Answers

Scene freezes after loaded 1 Answer

Scene loader Toutorial 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