Search Unity

[solved]change scene button

Discussion in 'UGUI & TextMesh Pro' started by gibberingmouther, Jan 18, 2017.

  1. gibberingmouther

    gibberingmouther

    Joined:
    Dec 13, 2016
    Posts:
    259
    https://hastebin.com/xehowipaso.cs

    you can see my code. i asked about this in irc and people (well, one person) said it should work. i linked to the script in the appropriate button and added in the name of the scene both with and without quotations. still when i click the button nothing happens. am i missing a step or something?

    edit: i also tried linking my "Exit" button to a method with Application.Quit(). this doesn't work either so i wonder if there's something i'm doing wrong in the editor. but i've been tinkering, i don't have a solution yet.

    the weird thing is that the editor still wanted a "name" parameter when this is a parameter-less script. hmmm....
     
    Last edited: Jan 18, 2017
  2. Izzy2000

    Izzy2000

    Joined:
    Dec 18, 2013
    Posts:
    49
    Was there once a Name parameter, which you removed later?
    If so, you must be using MonoDevelop. :)

    Close it and restart it. See if it still shows the old function.
     
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    If the method is executing, then make sure your scene is loaded before you try to set it active.
    If the method is not executing, make sure you have an EventSystem in the scene, this may be the situation if you are having buttons that don't appear to work at all. (since you mention other buttons also not working)
    If you have a screenshot of the inspector where the code is, that might help.
     
  4. gibberingmouther

    gibberingmouther

    Joined:
    Dec 13, 2016
    Posts:
    259
    yes, i was using monodevelop. i guess i mistook it for the correct function because the name of my parameter was "scenename" which is close to "name". so basically what i think is happening is it's not finding any methods in the selected script. i'm not sure why that is.

    i'm having trouble getting my new windows 10 laptop to take a screen shot so i can't show you unfortunately.

    i also tried adding in loadscene before switching the active scene but that didn't make any difference.
     
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    Windows 10 should have a program called snipping tool to use to cut out portions of your screen and make a png from it.

    And you do have an eventsystem in your scene?

    Just to make sure, but your script name in that link is xehowipaso.cs. That may just be how it is setup. But the class name is NewGameButton. These names don't match. Again, this may just be how your link set it up. But does your script and class name match?
     
  6. gibberingmouther

    gibberingmouther

    Joined:
    Dec 13, 2016
    Posts:
    259
    my class name and script name (NewGameButton and ChangeScene1) did not match, but i fixed that and the button still didn't work. i added the two scripts into a namespace, but that didn't do anything either.

    i think the problem is i can't get the buttons' On Click () feature to recognize the functions i have. does anybody know why this might be?
     
  7. Izzy2000

    Izzy2000

    Joined:
    Dec 18, 2013
    Posts:
    49
    wondering... are the functions Public?
     
  8. gibberingmouther

    gibberingmouther

    Joined:
    Dec 13, 2016
    Posts:
    259
  9. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    These scripts are on gameobjects in the scene(and not coming from prefabs), correct? Then on the button, it has onclick. You hit the plus, drag the gameobject into the slot. Then you'll have the drop down to select your script and function. You should see ChangeScene1 as the script with method sceneActive. Once that is selected, it will add an inputfield for your string scenename where you can type in the scenename.

    At what part does it not work?
     
    gibberingmouther likes this.
  10. gibberingmouther

    gibberingmouther

    Joined:
    Dec 13, 2016
    Posts:
    259
    i didn't do any dragging of gameobjects into any slots. that could be the problem. should i use an empty game object to attach the button press script to?
     
  11. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    You can pretty much attach the script to anything you want. But an empty gameobject works pretty well for something like this. Sometimes you'll put scripts on players or enemies, etc. But in this case, just create an empty gameobject. Attach the script to it, then drag it into the slot that appears on the button after you hit the plus sign. Then you'll need to use the second pulldown to select the class and function.
     
    gibberingmouther likes this.
  12. gibberingmouther

    gibberingmouther

    Joined:
    Dec 13, 2016
    Posts:
    259
    works now! thanks guys.