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 NinjaNeko · Dec 11, 2017 at 09:22 AM · unity 5textscene

Change scene using text UI ? help

alt text alt text

I want to change scene by the content of Text UI when I press Start

I add my C# script to Main Camera and give Text to C# script

and call changemenuscene when I press button

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 public class Changescene : MonoBehaviour {
 
     public Text Scenename;
     public void changemenuscene ()
     {
         //Debug.Log("Hi");
         Debug.Log (Scenename.text);
         Debug.Log (SceneManager.GetActiveScene ().buildIndex);
         //SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
         if (Scenename.text == "Dog") {
             Debug.Log ("Dogg");
             //Application.LoadLevel (1);
             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
         } 
         else if (Scenename.text == "Cat") {
             Debug.Log ("cat");
             //Application.LoadLevel (0);
             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);
         }
     }
 }
 

Debug.Log

Dog

UnityEngine.Debug:Log(Object)

Changescene:changemenuscene() (at Assets/Changescene.cs:13)

UnityEngine.EventSystems.EventSystem:Update()

0 UnityEngine.Debug:Log(Object)

Changescene:changemenuscene() (at Assets/Changescene.cs:14)

UnityEngine.EventSystems.EventSystem:Update()

in the yellow square fail to use if and else if, and I don't know how to solve this problem

thanks for your time to help

q4.png (7.1 kB)
q1.png (7.0 kB)
Comment
Add comment · Show 5
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 · Dec 11, 2017 at 09:25 AM 0
Share

What problem are your facing exactly? Who calls the changemenuscene function? How? Have you any error in the console? Do you see the output of the Debug.Log?

Please, remove the code image and copy-paste your actual code using the 101010 button.

avatar image NinjaNeko Hellium · Dec 11, 2017 at 09:47 AM 0
Share

I edit it can you help me check again? Thanks a lot

avatar image sethuraj · Dec 11, 2017 at 09:37 AM 0
Share

Hi, Are you sure the "changemenuscene()" function is getting called whenver required ?. If so make sure the scene name is spelled correct in the if-else and also dont forget to add all the scenes to "Scenes In Build" under File->BuildSettings

avatar image Hellium · Dec 11, 2017 at 09:52 AM 0
Share

Try this function in order to compare :

 if( String.Compare(Scenename.text.Trim(),"Dog", StringComparison.OrdinalIgnoreCase) == 0 )
avatar image NinjaNeko Hellium · Dec 11, 2017 at 10:24 AM 0
Share

thanks a lot I solved the problem

1 Reply

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

Answer by NinjaNeko · Dec 11, 2017 at 10:26 AM

Correct version

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 public class Changescene : MonoBehaviour {
 
     public Text Scenename;
     string String1 = "Dog" ;
     string String2 = "Cat";
     public void changemenuscene ()
     {
         //Debug.Log("Hi");
         Debug.Log (Scenename.text);
         Debug.Log (SceneManager.GetActiveScene ().buildIndex);
         //SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
         if( string.Compare(Scenename.text.Trim(),String1)==0 ) {
             Debug.Log ("Dog");
             //Application.LoadLevel (1);
             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
         } 
         else  if( string.Compare(Scenename.text.Trim(),String2)==0) {
             Debug.Log ("cat");
             //Application.LoadLevel (0);
             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);
         }
     }
 }
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

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

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

UI Text to scale with parent 0 Answers

Unity 5.2 Text Rendering issue 0 Answers

How to change scene without the previous scene being reset when you return? 0 Answers

Displaying a collision with Obstacle with text on screen? 0 Answers

Problem with Unity 4.6 UI Text 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