Step 1: Create three new folders under Unity Assets, materials, Scripts, Textures. Then drag three images into the Textures folder: planes, enemy planes and bullets. (You can go to 2D resource network and other places to download)

2. Step 2: In order to make the game run better experience, you can set the window size and Resolution, and so on, set the Resolution steps to select Edit | Project Setting | Player, then find Resolution bar set in the Default Screen Width is 800, The Default Screen Height is 600, then select the Game section at the top of the window and click on the Standalone Screen to select the 800 x 600 set as the window size.

3. Step 3: To add a game object to the scene, drag the aircraft and the enemy aircraft onto the screen, within the scope of the main camera. Next add the Collider primary button for the aircraft and the enemy aircraft. Click on the aircraft and you can see the Inspector on the right side of the Unity screen. Then select the Component below | Physics | Box Collider (the Box Collider has 2 d, 3 d, there are no major differences, when I am using 2 d). After adding colliders to both of them, I found that I could set the size in the X,Y, and Z directions, and set a range for this.

4. 4. Smart refrigerator Call it PlayerController. Double-click on this script. I’ll edit it in VS. If not, I suggest the next VS. The code below, some of the comments may not be very accurate, please bear with me.

using System.Collections; using System.Collections.Generic; using UnityEngine; Public class PlayerController: MonoBehaviour {// Number of units moved per second public float Speed; Public Vector3 MinMaxX = vector3.zero; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { Transform. position = New Vector3(Mathf.Clamp(// MathF. Clamp limits x movement range, input-getaxis ("Horizontal") gets keyboard left and right movement transform.position.x + Input.GetAxis("Horizontal") * Speed * Time.deltaTime, MinMaxX.x, MinMaxX.y), * * * * * * * * * * * * * * * * Y + Input.getaxis ("Vertical") * Speed * Time. DeltaTime, minmaxx.z, 5), transform.position.z ); }}Copy the code

5. 5. Smart refrigerator Once the code is written and saved, drag the script file to the Inspector on the right side of the screen, and you’ll see that there’s a PlayerController (Scripts) component that adjusts the Speed parameter and X, Y, Z, X, Y, Z, It represents the setting of the motion boundary of the aircraft. Then start the program, you can control through the keyboard up and down.

The above is the first part of the work, I will write the second part, until the completion of the middle will record some of the problems I encountered in doing this online game, as well as the solution.