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 /
This question was closed Nov 19, 2018 at 08:21 AM by kerenviner for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by kerenviner · Nov 14, 2018 at 12:26 PM · buttonsscenes

Unity Newbie: Buttons won't switch scenes

Hey sorry I am a Unity Newbie, but I am stuck. The buttons won't switch to the scenes, the buttons work and the code shows no errors. Someone recommended looking at the build settings, all my scenes are selected, so I am really lost. Please Help!

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 using UnityEngine.EventSystems;
 
 public class ChangeScene : MonoBehaviour {
 
     // Use this for initialization
     /*void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         
     }*/
     //detects which button is clicked
     public void detectClick()
     {
         //get the name of the current clicked object
         var theObject = EventSystem.current.currentSelectedGameObject;
 
         //take action depending on which object is clicked
         switch (theObject.name)
         {
             case "Microwave":
                 Debug.Log(theObject.name);
                 SceneManager.LoadScene("Coming_Soon");
                 break;
 
             case "RiceCooker":
                 Debug.Log(theObject.name);
                 SceneManager.LoadScene("Coming_Soon");
                 break;
 
             case "Stove":
                 Debug.Log(theObject.name);
                 SceneManager.LoadScene("Stove_Style");
                 break;
 
             case "S_African":
                 Debug.Log(theObject.name);
                 SceneManager.LoadScene("Coming_Soon");
                 break;
 
             case "S_Eastern":
                 Debug.Log(theObject.name);
                 SceneManager.LoadScene("Coming_Soon");
                 break;
 
             case "S_MiddleEastern":
                 Debug.Log(theObject.name);
                 SceneManager.LoadScene("Coming_Soon");
                 break;
         }
     }
 }
 
 
Comment
Add comment · Show 3
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 Hellium · Nov 14, 2018 at 12:50 PM 0
Share

Have you tried to print the name of the object outside of the switch block?

avatar image kerenviner Hellium · Nov 14, 2018 at 12:53 PM 0
Share

What do you mean by printing the name outside of the switch block?

avatar image Hellium kerenviner · Nov 14, 2018 at 01:10 PM 0
Share
  public void detectClick()
  {
      //get the name of the current clicked object
      var theObject = EventSystem.current.currentSelectedGameObject;

       Debug.Log( theObject.name ) ;
      // ...
  }

This way, you will be able to check whether you are clicking on the correct object

1 Reply

  • Sort: 
avatar image
0

Answer by AndresFelipeMendez · Nov 14, 2018 at 02:21 PM

Hello im a bit puzzled by the function detectClick, who calls it? i made a small sample with a cube and a collider listening in OnMouseDown() and replacing theObject.name with gameObject.name but the rest remain the same and it works, my guess is that your method detectClick is never called.

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 Hellium · Nov 14, 2018 at 03:18 PM 0
Share

detectClick is surely call as a callback of a button's onClick event.

Follow this Question

Answers Answers and Comments

98 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 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 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

Go to next scene when correct answer 3 Answers

An instance of type 'Timer' is required to access non static member 'paused' 1 Answer

2 Position GUI Texture Rocker Switch 0 Answers

can we have chance to put 2 actions for single button? -1 Answers

I need help, Everytime i put my scense in play it says, "Object reference not set to an instance of an object". Advice would be great:) 1 Answer


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