1. The first step: the first step is to realize the shooting system and motion system of the aircraft, and the next step is to realize the motion system of the enemy aircraft and the response when the bullet hits the enemy aircraft. This will also require a script file. We will also create a C# script EnemyController in the scripts folder. Double-click it and edit it.
using System.Collections; using System.Collections.Generic; using UnityEngine; Public class EnemyController: MonoBehaviour {public int Health = 100; Public float Speed = 1.0f; 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. PingPong(A,B)) transform.position = new Vector3(// mathf. PingPong(A,B)) Minmaxx.x + mathf. PingPong(time. Time * Speed, 1.0f) * (minmaxx.y-minmaxx.x), transform.position.y, transform.position.z ); } void OnTriggerEnter(Collider other) {Destroy(gameObject); Destroy(other.gameObject); }}Copy the code
Step 2: After writing and saving, drag the same code to the Inspector on the right of the EnemyController (scripts). EnemyController (scripts) adjusts the movement property of the EnemyController, where the EnemyController moves left and right constantly.
In the enemy planes and can be moved, and the movement of the aircraft and firing system is completed, the next was hit on the judge system, after I do here is the bullet hit the enemy, the enemy will disappear, the end of the code above has written about by enemy planes flying in and trigger, then there is the triggers, and it’s the card when I was the longest, for setting out the questions, The trigger doesn’t respond.
First of all, we click on the enemy plane. The component of the enemy plane has box collider. It doesn’t matter whether it has rigid body or not, but it must have collider. Double click the ammo default in Assets and go to the Inspector on the right side of ammo. The box collider is also required. If not, the bullet will pass through. Once set, the bullet hits and triggers the effector of the enemy aircraft, which then disappears.
This is a very small game, but the real participation in the development will find a lot of problems, but also learn a lot, in fact, there are many deficiencies, including the background, and the number of enemy planes, the movement of enemy planes, and the enemy planes fired bullets and so on, I will continue to develop and improve.