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 jessicalohse · Sep 09, 2017 at 11:17 PM · scene-switchingscene-changescene load

Switching Scenes Via Button Only Works for One Transition

Hi everyone,

I am attempting to make a game that allows the character to go to different scenes based on what they run into. I created a canvas that appears OnTriggerEnter that asks the player if they want to go to a certain scene, with buttons to confirm or deny (the functions for the onClick set in the Unity Inspector). This works correctly when I only have one transition in the scene. However, if I have two different objects that will take me to two different scenes, I can only ever go to one of the scenes. For example, if object A should take me to scene B and object C should take me to scene D, both objects will take me to scene B. I have tried this in multiple different ways, a canvas object for each transition object, one canvas object that just changes the data, assigning the button OnClicks in the script, etc., and none of it lets me transition correctly. When I debug the script, the sceneName is always the same, whether it is for object A or C. I have included the code for my transition script:

 public class SceneTransition : MonoBehaviour
 {
 
     public string message;
     public CanvasGroup textDisplayCanvas;
     public UnityStandardAssets.Characters.FirstPerson.MouseLook character;
     public CanvasGroup faderCanvasGroup;
     public string sceneName;
 
     // Use this for initialization
     void Start ()
     {
         textDisplayCanvas.alpha = 0;
     }
     
     // Update is called once per frame
     void Update ()
     {
         
     }
 
     void OnTriggerEnter (Collider col)
     {
         character.SetCursorLock (true);
         Text[] messages = textDisplayCanvas.GetComponentsInChildren<Text> ();
         messages [0].text = message;
         textDisplayCanvas.alpha = 1;
     }
 
     public void CancelTransition ()
     {
         character.SetCursorLock (false);
         textDisplayCanvas.alpha = 0;
     }
 
     public void TransitionToScene ()
     {
         textDisplayCanvas.alpha = 0;
         SceneController sceneController = FindObjectOfType<SceneController> ();
         sceneController.FadeAndLoadScene (sceneName);
     }
 }

Thanks for your help!!

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 IsaiahKelly · Sep 10, 2017 at 01:06 AM 0
Share

Your SceneTransition script ironically has nothing to do with the actual scene loading process. That's what SceneController apparently handles. So the sample code is useless for addressing the actual issue at hand. $$anonymous$$aybe you could post SceneController code ins$$anonymous$$d?

avatar image jessicalohse IsaiahKelly · Sep 10, 2017 at 01:20 AM 0
Share

I'm using the same SceneController from the Adventure Game Tutorial here: https://unity3d.com/learn/tutorials/projects/adventure-game-tutorial. The scene loading piece works correctly, but because the string sceneName is not always what I want it to be, it loads the incorrect scene.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by IsaiahKelly · Sep 10, 2017 at 11:00 PM

If you're using the SceneController script from the adventure game tutorial then you must have modified the FadeAndLoadScene method to accept a string instead of a SceneReaction object. So I assume that method looks something like this now:

     public void FadeAndLoadScene(string sceneName)
     {
         // If a fade isn't happening then start fading and switching scenes.
         if (!isFading)
         {
             StartCoroutine(FadeAndSwitchScenes(sceneName));
         }
     }

This method along with your SceneTransition script works perfectly fine for me. In my tests I added and set a new SceneTransition script for each UI button like so.

transition for scene B button

Perhaps you're accidentally calling the same script (which always loads scene B) on all buttons?


scene-transition-event.png (25.8 kB)
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 jessicalohse · Sep 11, 2017 at 12:06 AM 0
Share

By "calling the same script" do you mean the actual script SceneTransition.cs or the SceneTransition Component on the object?

I have attached screenshots of my buttons with the SceneTransition script attached. I still have the problem where using the transition loads the "Village" scene from both objects.

Button that should transition to inside school.

Button that should transition to the village.

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

70 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

Related Questions

Unity Scene loading problem (slow loading until it freezes) 0 Answers

Old scene still appears for short time when switching scene 0 Answers

Is there any ideas to load Unity scene asynchronously? 1 Answer

Most efficient way to transition between scenes? 1 Answer

Unity 2019.3.11f1 # Scene isn't changing, neither is the script working.,Unity 2019.3.11f1 | My script isn't executing. 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