Unity Version 5.5.2
This is what the cell phone Uidemo to get the sample map is like this
Content involved:
1. Three layers: Vines, the Sun, the sky, and the effect of depth of the landscape when scrolling
2. The mouse scroll when sliding when the vine can extend unlimited (the actual increase in the end of the top, if there are 100 layers, to 100 layers can not go up on the slippery)
3. The number on the vine is generated and placed on the vine.
Final figure
With three script controller (unlimited extension, termination), mover (to achieve the movement of all pictures), counter (to achieve the number generated on the picture)
Controller
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
public class Controller:monobehaviour {public Gameobject rawimage;
Public Gameobject start;
Public Transform Paneltrans;
Public Transform Curimagelow;
Public Transform Curimageup;
public int sign=0;
public int downstop=1; Use the to initialization public void start () {start = Gameobject.find (' Imagestart ');//For Bottom End}//Update is called once/frame public void Update () {if (start.transform.localposition.y >= 0) {downstop =
1; } if (curimagelow.localposition.y<0&&curimagelow&&sign<102) {//Generate new picture Gameobject NEX
Timage= Instantiate (rawimage,curimageup.transform.position,curimageup.transform.rotation) as GameObject;
NextImage.transform.parent = transform;
NextImage.transform.Translate (vector3.up*310);
Curimagelow = Curimageup;
Curimageup = Nextimage.transform; }
}
}
Mover
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
public class Mover3:monobehaviour {public int speed=500;
Public Gameobject Ctlgame;
Public Controller ctl;
Public counter Endcoutner;
Public Gameobject start;
Public Gameobject end; Use the to initialization public void start () {start = Gameobject.find (' Imagestart ');//For bottom end ctlgame = Gam Eobject.find ("Panel"); Used for Top End ctl = Ctlgame.
Getcomponent<controller> (); }//Update is called once per frame public void fixedupdate () {end = Ctl.curimageup.gameObject; Used for top stop Endcoutner = end.
Getcomponent<counter> ();
{if (Input.getaxis ("Mouse scrollwheel") < 0&&ctl.downstop==0) { Scroll down transform.
Translate (vector3.up * time.deltatime * speed);
} {if (Endcoutner.max = = 102 && end.transform.localposition.y <= 0) return; ElSe if (input.getaxis ("Mouse scrollwheel") > 0) {//scroll up ctl.downstop=0; Transform.
Translate (Vector3.down * time.deltatime * speed);
}
}
}
}
Counter
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
Public class Counter:monobehaviour {public
int []number=new int[115];
Public UnityEngine.UI.Text []textgroup=new unityengine.ui.text[6];
Public Gameobject ctlgame;
Public Controller ctl;
public int Max;
void Start ()
{ ctlgame = gameobject.find ("panel"); Assigns a
ctl = Ctlgame to an array. Getcomponent<controller> ();
for (int i = 1; i < number. Length; i++) {number
[i-1] = i;
}
Textgroup = gameobject.getcomponentsinchildren<unityengine.ui.text> (); Write a number for the text
(int j = 0; J < textgroup). Length && Ctl.sign < 114; J + +) {
Textgroup [j].text = number [ctl.sign]. ToString ();
ctl.sign++;
max = Ctl.sign;
}}}
And a second-tier sun script Sunmover the third-tier Sky script Skymover
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
public class Sunmover:mover3 {//The use this for
initialization public
void Start () {
base. Start ();
Speed = speed/100;
}
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
public class Skymover:mover3 {
//Use this for initialization
void Start () {
base. Start ();
Speed = speed/150;
}
Harvest:
1. To invoke a method or variable in the inherited class, you must add the method and the variable to public.
2. Call methods in other classes, variables (public). Start by declaring the public XXX class name first. Then write Name.function () in the function body, or name.var;
The scene in 3.UGUI is symmetric with the game view.
4. When modifying gameobjecttransform in canvas in the UI, use Transform.localposition.
5.findgameobject usage: public gameobject Start;start = Gameobject.find ("Imagestart");
6. There are many uses for creating objects instantiate, see official APIs for details
7. Modify the text content in the UI (if there are 6 text)
First declare:
Public UnityEngine.UI.Text []textgroup=new unityengine.ui.text[6];
Write in function:
Textgroup = gameobject.getcomponentsinchildren<unityengine.ui.text> (); Write a number in text
for (int j = 0; J < Textgroup. Length && Ctl.sign < 114; J + +) {
Textgroup [j].text = number [ctl.sign]. ToString ();
ctl.sign++;
}
8. Realize the infinite extension of the picture and can scroll to see. I used the method to automatically generate pictures and hang fixedupdate scripts on the pictures. The script implements, the mouse scrolls, the picture moves. Picture as a prefab, so that all the pictures have the same move up or down the function (mover is hanging on the prefab of the picture, automatically generated is prefab)
if (input xx) {transform. Translate (VECTOR3.XXXXXXX * time.deltatime * speed);}
if (enter yy) {transform. Translate (VECTOR3.YYYYYYY * time.deltatime * speed);}