[Unity3d] Inter-scene switching and data transfer (and object removal techniques)

Source: Internet
Author: User
Tags buy macbook pro buy macbook

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

First introduce some basic functions (use your own documentation):
--------------------------------------------------------
1. Scene Switching:application.loadlevel ("Level1")
2. Do not remove objects when reading a scene:Dontdestroyonload (object)//will be insuredany data that leaves the object, including coordinates, can be used in any object, including the GUI, and can be applied flexibly.
3. Set the object activation state (do this before removing the object, prevent the component from being removed in the running state):setactiverecursively (BOOL)
4. Remove the object (set his activation status to false before removing it):Destroy ()
5. Create a clone of prefab or other object:instantiate (XXX)

then introduce some basic knowledge:
------------------------------------------------------
1. Inter-file transfer can be usedStaticStatic type to bridge data (see my other blog), of course, the transfer between scenes can also.
2.Note that references and values are passedPass!! A.If you pass a reference type, but the reference is a scene object, then you have to use the second function above to preserve the object (otherwise the next scene refers to the content of the reference does not exist, will be wrong), so that in the new scenario can directly inherit his immediate attributes;B.Of course, if you preach this reference to a prefab, then there is no problem, if the current scene has changed the role data, then you pass the reference will also pass the changed properties, in the new scene to re-assign the value of the Prefab clone. (If you use a file to record the status of a role, it is best to use the B method)

Finally, examples are explained:
-------------------------------------------------------
target: Scene 1 Choose a car go-> scene 2 Use the selected car race
Process Introduction:
Scene 1 (Garage):

Pick a car (there are several cars to choose from), and then pass this car's prefab reference to a JS file in the static variable to store

Enter Scenario 2:

Clone the previously referenced prefab in the original ground-specified coordinates to accomplish the goal (note that the code sets some data, such as camera tracking parameters, etc.).
The opponent car is random ^ ^ principle, just do not need to pass the value, set the coordinates randomly generated AI can be.

==============
Now hate to have no money to buy MacBook Pro and iphone, the game is basically shaped, on the iphone on the touch debugging, functional performance Testing and interface debugging.
Hey, grab the apple and get back-,-first.

[Unity3d] Inter-scene switching and data transfer (and object removal techniques)

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.