[Unity3D] scenario switching and data transfer (as well as object deletion techniques)

Source: Internet
Author: User

First, we will introduce some basic functions (for specific usage, refer to the document ):
--------------------------------------------------------
1. Scenario switching: Application. LoadLevel ("Level1 ")
2. When reading a scenario, do not remove the object: DontDestroyOnLoad (object) // retains any data of the object, including coordinates, which can be used for any object, GUI, and flexible use.
3. Set the active state of the object (execute this operation before removing the object to prevent the component from being removed in the running state): SetActiveRecursively (bool)
4. Remove an object (set its activation status to false when the object cannot be removed): Destroy ()
5. Create a clone of prefab or other objects: Instantiate (xxx)
 
Then we will introduce some basic knowledge:
------------------------------------------------------
1. The static type can be used for inter-file transfer to bridge data (see my other blog). Of course, the transfer between scenarios is also acceptable.
2. Pay attention to reference and value transfer !!A.If you upload a reference type, but the referenced content is a real object of the scenario, then you need to use the second function above to keep the object (otherwise, the reference content in the next scene will not exist and will make an error ), in this way, all its real-time attributes can be directly inherited in the new scenario;B.Of course, if the reference you passed points to a prefab, this problem will not exist. If the current scenario has changed the role data, after passing the reference, you must also pass the changed attributes. Fortunately, in the new scenario, you can assign a new value to the prefab clone. (If you use a file to record the role status, it is best to use the B method)
 
Finally, an example is provided:
-------------------------------------------------------
Objective: To select a vehicle in scenario 1GO->Scenario 2 use the selected vehicle Competition
Process introduction:
Scenario 1 (garage ):

Select a car (there are several cars to choose from), and then pass the prefab reference of the car to the static variable of a js file for storage.
 
Scenario 2:

Clone the referenced prefab from the coordinates specified on the ground to complete the target (note that the Code sets some data, such as camera tracking parameters ).
The principle of the opponent's car is the same as that of the random ^, but it does not need to pass the value, just order the coordinates to generate AI at random.
 
====================

Now, I hate myself for having no money to buy a MacBook pro and an iphone. The game is basically formed, and the hand-feel debugging, functional performance testing, and interface debugging on the iphone are poor.


Reprinted: http://blog.163.com/kingmax_res/blog/static/77282442201031712216508/

Related Article

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.