Unity is also easy to do 2D projects. To adjust the camera mode first, the camera's view panel parameters are as follows:
Perspective mode is the usual mode. The camera to the game object is angled open, and the orthographic mode is not, the difference between the two from the side of the view on the glance:
Perspective type
Orthographic
These two pictures are to intercept the rain Pine predecessors of the figure, this is the side view, I believe we see the difference at a glance, no longer too much explanation;
Here is the mobile chapter, press WASD to control the camera up and down around the move. Press IJKL to control the movement of the foal (when pressed, the foal sequence diagram is played, and the last frame is stuck when released).
The picture is in JPG format, because the error of transduction is not saved in PNG format, it is used in JPG format. So shader choice of what shader also not important I used transparent/diffuse this bring shader;
Buy code I say a J8:
1 usingUnityengine;2 usingSystem.Collections;3 4 Public classMovetest:monobehaviour5 {6 Privategameobject horses;7 Privateobject[] images;8 Private floattimer;9 Public floatfps=10f;//10 frames a second;Ten Private intcurrentframe; One //Use this for initialization A voidStart () - { -Gameobject plane = Gameobject.find ("Plane"); the //get face Default width - floatsize_x = plane. Getcomponent<meshfilter>(). mesh.bounds.size.x; - //get the zoom ratio of the width - floatscal_x =plane.transform.localscale.x; + //get face Default height - floatsize_z = plane. Getcomponent<meshfilter>(). mesh.bounds.size.z; + //get the polygon height scale A floatScal_z =plane.transform.localscale.z; at - //the original width multiplied by the scale to calculate the true width - floatMapwidth = size_x *scal_x; - floatMapheight = Size_z *scal_z; - -Debug.Log ("get the position of the face:"+plane.transform.position); inDebug.Log ("get the width of the polygon:"+mapwidth); -Debug.Log ("get the height of the face:"+mapheight); to +Horses = Gameobject.find ("player"); -Images = Resources.loadall ("xulieimages") asobject[]; the } * $ //Update is called once per framePanax Notoginseng voidUpdate () - { the if(Input.getkey (keycode.a)) { + This. Transform. Translate (-0.1f, 0f, 0f, Space.world); A } the if(Input.getkey (KEYCODE.D)) { + This. Transform. Translate (0.1f, 0f, 0f, Space.world); - } $ if(Input.getkey (KEYCODE.W)) { $ This. Transform. Translate (0f,0.1f, 0f, Space.world); - } - the if(Input.getkey (KEYCODE.S)) { - This. Transform. Translate (0f,-0.1f, 0f, Space.world);Wuyi } the //This is horse ' s: - if(Input.getkey (KEYCODE.J)) { WuHorses.transform.Translate (-0.1f, 0f, 0f, Space.world); - drawimages (images); About } $ Else - { -Horses.renderer.material.maintexture=images[currentframe] asTexture; - } A if(Input.getkey (KEYCODE.L)) { +Horses.transform.Translate (0.1f, 0f, 0f, Space.world); the drawimages (images); - } $ Else the { theHorses.renderer.material.maintexture=images[currentframe] asTexture; the } the if(Input.getkey (keycode.i)) { -Horses.transform.Translate (0f,0.1f, 0f, Space.world); in drawimages (images); the } the Else About { theHorses.renderer.material.maintexture=images[currentframe] asTexture; the } the + if(Input.getkey (KEYCODE.K)) { -Horses.transform.Translate (0f,-0.1f, 0f, Space.world); the drawimages (images);Bayi } the Else the { -Horses.renderer.material.maintexture=images[currentframe] asTexture; - } the the } the the Public voiddrawimages (object[]useimages) - { thetimer+=Time.deltatime; the //sequence diagram switching function the if(timer>=1.0/fps) {94currentframe++; theTimer=0; the //overflow zeroing; the if(currentframe>=useimages.length) {98Currentframe=0; About } - }101Horses.renderer.material.maintexture=useimages[currentframe] asTexture;102 }103 104 the 106}
The script I hung it on the game object main Camera. The player is a plan object:
The dynamic change is the main map of the material of the play, the above script uses the Resources.loadall function, the following explains how this function is used and an official case:
Resources.loadall Load All
static function Loadall (path:string, Type:type): object[]
Load the path folder in the Resources folder or all the resources in the file.
If path is a folder, all resources in the file will be returned. If path is a file, only this resource will be returned. Only types of objects of type will be returned. Path relative to the resources folder. The resources folder can be anywhere in the assets folder.
//加载"Resources/Texture"文件夹中所有资源//然后从列表中选择随机的一个//注意:Random.Range这里返回 [低,高)范围,例如,高值不包括在内。
1 usingUnityengine;2 usingSystem.Collections;3 4 Public classExample:monobehaviour {5 voidStart () {6Gameobject go =gameobject.createprimitive (primitivetype.cube);7object[] Textures = Resources.loadall ("Textures",typeof(texture2d));8Texture2d texture = Textures[random.range (0, textures. Length)];9Go.renderer.material.mainTexture =Texture;Ten } One}
Unity's 2D Game simple operation