• 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 /
  • Help Room /
avatar image
0
Question by TrustEditz · Dec 19, 2015 at 12:23 PM · application.loadlevelinput.getbutton

Changing scene by pressing a key

Hiya! So I'm working on a game completely on my own. I'm not good at all with unity or coding. So my problem is that I want to stand in a cartain area and press a button, which then switches scenes to where you can buy guns (other scene). My code atm looks like this

  void OnTriggerEnter(Collider other)
         {
             if (other.gameObject.tag == "Player")
             {
                 ContinueText.text = Continue;
                 helpText.text = "";
             }
                 if (Input.GetButtonDown("Use"))
                 {
                     Application.LoadLevel("Shop");
                     Debug.Log("Loading level: Shop");
                 }

I added "Use" to the input manager aswell. Anyone knows what I can do to make it work? Atm I don't get any errors.

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

2 Replies

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

Answer by TrustEditz · Dec 02, 2016 at 10:35 AM

If anyone is googling and comes to this topic, the answer was in the function. Instead of using OnTriggerEnter, which only runs when you enter the object. Use OnTriggerStay, which runs as long as you're inside the trigger

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 usalalas · Dec 19, 2015 at 12:30 PM

Did you add a breakpoint on line 10 to see if the debugg stops there?

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 TrustEditz · Dec 19, 2015 at 12:34 PM 0
Share

Don't understand what you mean. Care to show me what you mean?

avatar image usalalas · Dec 19, 2015 at 12:41 PM 0
Share

Well, In $$anonymous$$onodevelop you can add a breakpoint to that line, to see if the script enters there.

avatar image TrustEditz usalalas · Dec 19, 2015 at 12:55 PM 0
Share

I'm using Visual studio

avatar image usalalas · Dec 19, 2015 at 12:44 PM 0
Share

Did you also added the scene in the build settings?

avatar image TrustEditz usalalas · Dec 19, 2015 at 12:54 PM 0
Share

yeah, I have

avatar image usalalas · Dec 19, 2015 at 12:57 PM 0
Share

I'm not used to Visual Studio, but you should be sure that this line is been executed. That's why I asked about the breakpoint.

avatar image TrustEditz usalalas · Dec 19, 2015 at 01:09 PM 0
Share

Yeeeeah, tried it, don't get a notification, even on line of code that runs

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Question regarding OnTriggerEnter and Application.LoadLevel 1 Answer

Input key is taken into account several times 1 Answer

Application.loadlevel adding double scripts to objects 0 Answers

Double Input.GetButton problem. 1 Answer

Application.LoadLevel problem 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges