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 KittyCrafting · Jan 04, 2014 at 12:22 AM · sceneloadchangelevelapplication

Click Object to change scene

I have a script for when i click my game object (box) it changes scenes but when i click it, it just restarts my menu scene E.G game objects start from where they do but its supposed to change scenes to the actual game

SCRIPT:

 function Update () {
     if(Input.GetMouseButton(1))
         Application.LoadLevel("NewGame");
     }
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 KittyCrafting · Jan 04, 2014 at 11:56 PM -1
Share

Ok it worked after a bit of fiddling thanks for your help

$$anonymous$$ittyCrafting.

avatar image KittyCrafting · Jan 04, 2014 at 11:56 PM -1
Share

ok thanks for the code the scene was in build list im going to try it now. The objects do have colliders.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiloblargh · Jan 04, 2014 at 12:30 AM

Should be Input.GetMouseButtonDown(0) for a left click.

GetMouseButton(1) will take a right click and continue to spam Application.LoadLevel messages every frame the mouse button is held down, which could result in a crash.

Neither one detects a click on the box. You should use a collider and a Raycast to make sure that the cursor is over the button when you click, otherwise a click anywhere will load the level.

Also, you have to make sure that all your scenes are added to the project in build settings- they are not by default.

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 valim · Jan 04, 2014 at 02:24 PM

If you want to build that only for PC here's the code:

 private var startedLoad : boolean = false;
 function OnMouseDown(){
   if(!startedLoad){
     Application.LoadLevel("NewGame");
     startedLoad = true;
   }
 }

And as Kiloblargh said, you have to make sure that all your scenes are added to the project in build settings.

And the object you attach this script must have a collider.


The boolean is that you can't spam the LoadLevel function.

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 midnightblackplanet · Jun 30, 2014 at 08:00 PM 0
Share

Hey, thanks for your answer, helped me 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

19 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

Related Questions

Random level select 1 Answer

Application.LoadLevel strange problem 2 Answers

Load last scene/level 4 Answers

How to see what level is running? 2 Answers

Multiple Instances of My Current Scene? 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