Thursday report on the first week of soft engineering course

Source: Internet
Author: User

Name

Zhang Yi

Time

June 30, 2016

Learning content

Today I have addressed another issue that the user has reflected. At the beginning of the design phase, we only designed a background for the overall atmosphere of the game, without considering the needs of the user for a variety of backgrounds. In view of this problem, we mainly added two new styles of different backgrounds, so that the hue has changed,

The biggest question in the process of joining the background is how to change the background of each scene. Since Unity's loading unit is a scene, changing the background of the current scene does not affect the background of the next scene, and each of our levels is stored for a scene, making it more difficult to change the background. The original situation is that the background in each scene is static and does not change, but the requirement now is that the changes made in the menu will be reflected in each level.

Uimanager is a singleton, in the entire game is responsible for storing the current level and other information, in the loading of the various levels he will be kept into the new level, so it is very appropriate to store background information, but only storage is not enough, changing the background is equally important, but the timing of replacement is also a problem.

The Unity Loop consists of start and update two functions, start is executed at initialization, and update executes at each frame. It is not necessary to have a waste of resources if you are testing the current background at every frame. We want to detect if the background is the desired background whenever a new scene is loaded, or if it is not replaced. But the question is how to seize the moment. As mentioned earlier, start executes at initialization time, but as mentioned above, the Uimanager is not created repeatedly between scenes, but is kept in a new scene, which means that its start will not be executed. So how do we seize the moment?

The method is very simple, although the Uimanager will not be created repeatedly, but our protagonist will be initialized in each scene, which means that its start function is executed every time the new scene is loaded. So we call Uimanager's updated background function in the start function of the protagonist.

The code is as follows:

void Start ()

{

Other code ...

Uimanager = Gameobject.find ("Uimanager");

Uimanager.sendmessage ("syncbkg");

}

private void syncbkg ()

{

Gameobject bkg1 = Gameobject.find ("Bkg1");

if (BKG1)

{

Spriterenderer Spriterenderer

= Bkg1. Getcomponent<spriterenderer> ();

if (spriterenderer)

{

Spriterenderer.sprite = bkgs[bkg];

}

}

}

As follows:

Added a new menu option

Added a button to replace a new background

New background can be updated correctly when loading new scenes

The problems encountered

So far no problems have been encountered

Solution Solutions

No

Thursday report on the first week of soft engineering course

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.