Button to new scene


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 ()

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?

Daniel Colthart

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

if (do somthing) {



else if (do somthingelse) {


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

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”.