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 KnightRiderGuy · Sep 07, 2015 at 12:35 PM · cameraguiscenecamerasswitching

Camera Switching or Scene Changes?

Ok this is something I have been kind of wondering for a while now. Lets say by application is simple just one big GUI or in my case many GUI's, I have them currently in different scenes but some of the problems I have is when I change scenes things get lost like "Trip Counters" and states of a button being on or off from the previous scene. I have heard that Singletons or whatever they are called can cure that but I have not been able to wrap my head around them or have any progress trying to figure them out.

Would just camera switching maybe be a better way to go in my case? Like for instance if I took all of the GUI's from all the separate scenes and imported them into one scene that had a camera set up for each of the GUI's. Or would that just make things more complicated?

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by cjdev · Sep 07, 2015 at 09:39 PM

Scenes can be useful as a way to organize a game, especially with large static levels. Personally though, I like to run my game with scripting in one scene with just an empty GO and scripts attached. Then I can instantiate anything I need on demand, such as GUI prefabs, whenever I need it and destroy it when I don't. But it's really just a matter of preference, the scene objects are there for your convenience so you should use them or not as your project demands.

Singletons are essentially just objects where only one of them can exist. You can create one to store data and have it not be destroyed when your scene changes so that your data persists between scenes. Camera switching isn't something I would recommend unless perhaps you need it for a small application just because of the added overhead the extra instantiated items create when you don't need them.

Comment
Add comment · Show 12 · 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 KnightRiderGuy · Sep 08, 2015 at 12:33 AM 0
Share

Thanks for responding cjdev, For a project like this what do you think would be the best way to go, scene changes for each different interface screen or camera switching, keeping in $$anonymous$$d too that Arduino is being used to communicate to external devices through the serial port.

Take a look at this video to get an idea of the scope of the overall project ;) [Demo Video][1] [1]: https://www.youtube.com/watch?v=IbD81ur$$anonymous$$0lw

avatar image cjdev · Sep 08, 2015 at 01:42 AM 1
Share

With that many GUI screens and an external connection to worry about I guess I'd go with camera switching if it has to be a choice between the two. Ideally though making each screen a prefab and loading them from the Resources folder would make it much easier to deal with all of them.

avatar image KnightRiderGuy cjdev · Sep 10, 2015 at 04:21 PM 0
Share

Thanks cjdev, I'm using canvases for my GUI how would I go about managing so many different ones, like switching between them? Is there a tutorial anywhere that you know of that walks you through the whole process?

avatar image cjdev KnightRiderGuy · Sep 10, 2015 at 07:07 PM 0
Share

I'm not aware of any specific tutorials but the process is actually fairly straightforward. You just need to have an EventSystem in your Scene and then you make a prefab out of each of your Canvas objects and put them in a folder named Resources. Then when you want to load that Canvas you just do:

 GameObject canvas = Resources.Load("CanvasPrefab") as GameObject;
 Instantiate(canvas);

This way you can Instantiate and Destroy your Canvases on demand because you have access to the prefabs as a reference.

Show more comments
avatar image KnightRiderGuy · Sep 11, 2015 at 01:11 AM 0
Share

What if my timer text is on a canvas and it gets unloaded would that not effect the timer like stop it for instance?

avatar image _Gkxd · Sep 11, 2015 at 02:51 AM 0
Share

Ins$$anonymous$$d of instantiating/destroying GameObjects, it might be easier to enable/disable them ins$$anonymous$$d. You can just drag the canvases (or any other GameObjects) into some public variables in a script that will enable/disable all of them. This removes the need for making prefabs.

avatar image KnightRiderGuy _Gkxd · Sep 11, 2015 at 12:14 PM 0
Share

Thanks Gkxd, Now would that be a good option give that I have a lot of canvases to work with, currently they are in different scenes but if they were all somehow merged into one scene would that still be a good idea?

$$anonymous$$eep in $$anonymous$$d these are full screen GUIs with a full screen PNG as the background with swapping graphic buttons on top of them, some full screen animations too.

avatar image _Gkxd KnightRiderGuy · Sep 11, 2015 at 01:11 PM 0
Share

You can essentially just drag everything into one scene, and hit the checkboxes in the inspector to disable/enable them. I haven't tried having multiple canvases in one scene, but I think it will work.

You can use a script to toggle those checkboxes by using GameObject.SetActive().

avatar image cjdev · Sep 11, 2015 at 04:09 AM 0
Share

While your timer text object would be destroyed (if you were instantiating and destroying GameObjects) the timer variable you use to keep track of time would not be as it would reside in another class and object entirely, say a 'Timer' script component on a 'GlobalScripts' GameObject.

avatar image KnightRiderGuy cjdev · Sep 11, 2015 at 12:16 PM 0
Share

Thanks cjdev, This sounds like a very good solution, I sure wish though that three was a tutorial that explained this in step by step detail just so I could comprehend the process better.

avatar image
1

Answer by chomps32 · Sep 11, 2015 at 04:40 PM

Scene switching is going to be the best way to keep your game clean and simple. The basics of Singletons is this:

1) There can only be one in your game. 2) Every object in the game can access its data.

Here is an example of a simple singleton:

public class Singleton : MonoBehaviour {

 // Static singleton property
 public static Singleton Instance { get; private set; }

     bool accessableData; //type Singleton.Instance.accessableData to access this data from any other class
 
 void Awake()
 {

     // First we check if there are any other instances conflicting
     if(Instance == null)
     {
         // Furthermore we make sure that we don't destroy between scenes
         DontDestroyOnLoad(gameObject);
         Instance = this;

     }else
     {
         //if the gameObject is already on the scene
         Destroy(gameObject);
     }

 }
 

}

Watch this video to get further explanation. Including how to switch between scenes and why the Singleton is used.

https://www.youtube.com/watch?v=J6FfcJpbPXE

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
avatar image
0

Answer by KnightRiderGuy · Sep 12, 2015 at 04:16 PM

Chomps32, Ok i took a look at that tutorial, they are using the on GUI stuff and I'm using UI text for my trip timer. I'm not sure what I'm missing, I made this script and put it on an empty game object and then made a prefab of it.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class InterfaceControl : MonoBehaviour {
 
     public static InterfaceControl control;
 
     public GameObject timeText;
     public int time = 00;
     
     void Awake () {
         if (control == null) {
             DontDestroyOnLoad (gameObject);
             control = this;
         } else if (control != this) {
             Destroy (gameObject);
         }
 
     }
     
     // Update is called once per frame
     void Update () {
         timeText.GetComponent<Text> ().text = "00:00:00:00"+time;
     }
 }
 

I them made a prefab of my "TmerText" and saved that as a prefab (Not sure if I needed too)? But I'm not getting something as I can't seem to get my timer to keep it's count across a scene change. I have attached a screen capture of my Hierarchy, inspector and prefabs folder, hopefully it will help?

[1]: /storage/temp/54169-screen-shot-2015-09-12-at-111309-am.png


screen-shot-2015-09-12-at-111309-am.png (194.5 kB)
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

31 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

Related Questions

Multiple Camera Switching 1 Answer

How do i remove the gui windows in my scene 1 Answer

have a camera from a different scene? 1 Answer

Display 2 Scenes at Once 1 Answer

ASP .NET: How do I link gui components to Unity web player? 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