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 DcoltGaming · Sep 23, 2016 at 11:44 AM · buttonscenescene-loading

Button to new scene

Hi,

I have a problem where I can't seem to get my java code to work to switch to a new scene. I have the code linked to the "OnClick" event of the button.

The code it:

 #pragma strict
 
 function LoadScene ()
 {
 Application.LoadLevel("MainGame");
 }
 

However, when I go into the function select, next to "Runtime only", the LoadScene function is not there, as if it is not detecting the function.

How do I fix this?

Thanks Daniel Colthart

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 yasser_kaddoura · Sep 23, 2016 at 06:20 PM 0
Share

$$anonymous$$aybe you forgot to save the script? or you picked the wrong object to pick the script from?

avatar image DcoltGaming yasser_kaddoura · Sep 23, 2016 at 06:46 PM 0
Share

$$anonymous$$aybe, I have just gone into unity, and now I can only select No Function or $$anonymous$$onoscrip -> string name

3 Replies

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

Answer by DcoltGaming · Sep 25, 2016 at 01:43 PM

Restarting and re-adding the script to an empty got it to work.

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 Damastasam · Sep 23, 2016 at 07:09 PM

You may need to write some code that calls the LoadScene function. Like an if statment

 if (do somthing) {
 
 LoadScene()
 
 }
 
 else if (do somthingelse) {
 
 }
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 DcoltGaming · Sep 23, 2016 at 07:12 PM 0
Share

So would I need to add in onClick()?

avatar image
0

Answer by aditya007 · Sep 25, 2016 at 01:43 PM

Hi @DcoltGaming I don't really know about java, but in C# you need to make the function "public" for it to be visible in the methods list.So, check whether you need to do it in java or not. And also check again whether you have assigned the gameObject, on whom this script is attached, below the "Runtime Ony".

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 DcoltGaming · Sep 25, 2016 at 03:01 PM 0
Share

Hi $$anonymous$$ate,

All sorted now. I restarted and reassigned to a new empty and it worked. Thanks for your answer though.

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

6 People are following this question.

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

Related Questions

Using UI.Button to Load Another Scene? (using outdated tutorial video) 1 Answer

buttons not being able to be clicked? 1 Answer

Load and run scene in background 1 Answer

Load new Scene with LoadSceneMode.Additive - I cannot interact with the new Scene, although it was set as Active Scene 0 Answers

Only one scene? 2 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