Unity 3D Cool running game scene loop

Source: Internet
Author: User

Unity 3D Cool running game scene loop

2015/07/05/////////////

by xbw////////////////////

Environmental unity4.6.1//////

After a morning of study and experiment, finally realized the 3D cool running game scene cycle. Exultation. Then share the exchange and learn together.



In the scene built two plane as the ground, respectively named as Plane1,plane2;

Position were set to 0,0,50;0,0,150;

The scale is set to 1,1,10;1,1,10 respectively;

Then set up a cube, the position is set to 0,0.5,20;

Cube is a game character,

The direction control code of cube;; CSharp code is as follows;


Using unityengine;using System.collections;public class playcontrol:monobehaviour{public   float Movespeed =10f;< C4/>void Update () {    if (Input.getkey (keycode.uparrow))             transform. Translate (Vector3.forward * movespeed*time.deltatime);           if (Input.getkey (keycode.downarrow))           transform. Translate (Vector3.back * movespeed * time.deltatime);        if (Input.getkey (keycode.leftarrow))           transform. Translate (Vector3.left * movespeed * time.deltatime);        if (Input.getkey (keycode.rightarrow))          transform. Translate (vector3.right * movespeed * time.deltatime);    }}
Create a C#script ...
Write this code to the cube;
To add a unity-brought script to the master camera,
To add a procedure:
import can be;;;
We'll see more out of the Code folder;
The Smoothfollow is entrusted to the main camera, main cameras;;;
At this point the operation can see the effect, you can use the arrow keys to control the cube movement, we have to solve the problem is the scene loop,
How to achieve the two plane plane generation infinite loop scene, two plane a previous one, through the front of the plane moved him to the back of a plane behind;
And will Plane1 delete, walk through Plane2, Plane2 disappear, move to the back of Plane3, an alternating cycle, realize the wireless road of the scene;;;
In order to achieve better results, the cube is first added gravity effect, there are some related properties, as follows;

where we added tag ———— Player to Cube ...

Added the Box Collider property,,,

Next add two tags named plane1,plane2;

in this name;;;;;;

Sub-categories of tag-plane1,tag-plane2 as Plane1,plane2, respectively;;;;

Set up a bit

Tag-plane1,tag-plane2;



You found the code?;;;

This is used to control two plane alternating cycles;;;;;

The code is as follows;;;;

Using unityengine;using system.collections;public class bgtrigger:monobehaviour{    gameobject BG;    void Start ()   {bg = new gameobject ();}    void Ontriggerenter (Collider e)   {       if (E.comparetag ("Player")) {if (GameObject.transform.parent.CompareTag (" Plane2 "))//Parent class            {                bg = gameobject.findgameobjectwithtag (" Plane2 ");                 Bg.transform.position = new Vector3 (0, 0, bg.transform.position.z +);            }            else            {                bg = gameobject.findgameobjectwithtag ("Plane1");                 Bg.transform.position = new Vector3 (0, 0, bg.transform.position.z + +);}}}    

Box Collider is a trigger,,,,,,

When cube goes to this position, it touches the trigger, and the corresponding code will work;;;;

Look at the position of the two triggers I set, to ensure sufficient overlap, the first is always error,

Found that the trigger is exactly at the end of the two road, so that the cube will go to two road between the time of the physical phenomenon, resulting in the cube lost direction, dropped;;

Enough reorganization can make the picture smooth,,, not to see a part of the scene;;;;;;

I put two trees next to the trigger is to test the location of the road when it is generated, to facilitate the adjustment of the location of road generation;;;;


As for the road map, directly build materials, entrusted to plane, no longer say;;;

Here, almost, quickly follow the realization of it, the narrative is not very clear, there are questions I will promptly give a reply,, and joint learning exchange;;;;,

Beginners, do not like to spray,,, Unity Daniel please Detour;;;;




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Unity 3D Cool running game scene loop

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.