Fight Aircraft Combat module:
First, scene management:
1. Both sides enter the scene effect (for example: fly in sequence)
About animation, here we are using the dotween component, the specific use of the method can be seen in my previous blog:
http://blog.csdn.net/linshuhe1/article/details/51331569
2. End of battle until the next battle starts over effects (for example: The screen fades, the victory side of the plane flies out of the screen display range)
Shady effect: Also using the plane component, but the type of shader used at this time, we need to write the shader file ourselves, and then bind a script in plane to control the gradient effect of the transparency value of the color property in shader
3. Background image effect (wheel roll)
Implementation: Two plane binding a script, theUpdate method in the gradient coordinates , to a certain threshold to reset the coordinates, both on the screen, the size of the plane is at least larger than the screen display range (prevent background discontinuity), create a legacy shaders/ Diffuse type of material ball material, and drag and drop the image on the binding material, the material ball by dragging to fill the material property of the mesh renderer in plane
Toggle background: Load a picture file of the Texture property of the path specified below the Resources folder by resources.load<texture> ("path") and copy the Texture to the Mesh Renderer the Material.maintexture property of the component to toggle the background map
Second, the skill system:
1. Passive skill: Also AI for automatic combat
The first is the selection logic of the attack object, according to the design, the order of attack is: first attack the opponent on the bit, the position of no opponent to attack near the nearest distance, the same distance to choose the higher blood volume.
2.Buff: Injury, regeneration, etc.
Create a new Basebuffer script, all the buff messages sent by this script is unified processing, the buff message must contain a few basic information: the impact of the Buff object, the buff type, the Buff attribute value, the buff's emitted object's properties (just attributes, not object entities, Anyway, the buff hasn't finished yet. The emitted object has been destroyed, which can easily lead to an empty object reference error.
3. Blood Bar:
There are two main ways to achieve the blood bar, one is to directly design the blood bar into a three-dimensional scene of an object bound to the hero , and set the blood bar in real-time alignment of the camera direction, the other is by converting the coordinates of the hero in 3D space to 2D space coordinates , The 2D component is then used to create the blood bar, and in real time to get the hero's 3D coordinates converted 2D coordinates, and assigns a value to the blood bar.
4. Bullet system:
In hierarchy, right-click Create empty to create a null object named Bullet, and under which a 2D object sprite (a picture for displaying bullets) is named Bulletsprite:
Since the bullet is actually a collision event with the attacking object, the bullet needs to add the collision component box Collider, which can adjust the size of the collision box according to the size of the bullet picture or model:
Every bullet we need to bind a script to define some basic properties of a bullet, handle collision events, and control the movement and disappearance of bullets, here we create a Bullet.cs script, the key is to rewrite Ontriggerenter( ColliderOther) method, which is the method that is triggered when a collision event occurs, that is, all of our handling of the collision event is written here, where other is the target object to be collided with:
<summary>///Bullet and Aircraft Collision box Event///</summary>///<param name= "other" >Other.</param> protected void Ontriggerenter (Collider other) {//To own team invalid if (This.tag = = Other.tag) return; Bullets disappear Destroy (gameobject); A buff message occurs datastructs.demagedata demage_data = new Datastructs.demagedata (); Demage_data.target = Other.transform; Demage_data.type = 0; Demage_data.num = power; Basebuff.receivedemage (Demage_data); }
As for the movement of bullets, that is, the change in the space position of bullets, in the Update Dynamic modification localposition to achieve, the specific idea can be set up a direction vector, that is, a Vector3 type of data, with the speed vector multiplied by the speed value multiplied by the length of time, That is to get the space displacement, and then superimposed to the original position can be a new position can also be limited to a range of bullets automatically destroyed (improve efficiency):
<summary>///bullet Position Change//</summary>void Update () { //game pause if (BattleManager.Instance.IsPause = = true | | Ispause = = true) return; Mdirection is the direction vector, speed is the value var position = mtransform.localposition + mdirection * tempo * time.deltatime; if (position.z <= -7.11) { Destroy (gameobject); return; } Mtransform.localposition = position; }
5. Active skills: big strokes (e.g., lunge, transposition, long Press)
Gesture recognition: OnMouseDown, OnMouseUp, Onmousedrag
Using unityengine;using System.collections;public class Actorhandlecomponent:monobehaviour {Private Vector3 _ vec3targetscreenspace;//the screen space coordinates of the target object private Vector3 _vec3targetworldspace;//the world space coordinates of the target object private static Transform O riginal_trans;//position before dragging private Transform _trans;//the spatial transformation component of the target object private Vector3 _vec3mousescreenspace;// Mouse screen space coordinates private VECTOR3 _vec3offset;//offset private camera[] mycamer; Private Camera Selfcamer; <summary>////three gesture recognition///</summary> public enum Handletype {slideup,//Slide up Changeposition,//transposition longpress//Long press}void awake () {_trans = transform;} Use the this for initialization void Start () {Mycamer = new camera[5]; Self = transform. Getcomponent<actor> (); Original_trans = Battlemanager.instance.m_pos[0]; Camera.getallcameras (Mycamer); foreach (Camera A in Mycamer) {if (a! = null) {if (a.taG = = "Uicamera") {//get uicamera Selfcamer = A; }}}}ienumerator OnMouseDown () {Debug.Log ("mouse Message *****************************onmousedown" )//Convert the world space coordinates of the target object to its own screen space coordinates _vec3targetscreenspace = Selfcamer.worldtoscreenpoint (_trans.position);//Store the mouse's screen space to sit (Z-Values use the screen space coordinates of the target object) _vec3mousescreenspace = new Vector3 (input.mouseposition.x, INPUT.MOUSEPOSITION.Y, _ VEC3TARGETSCREENSPACE.Z); Calculates the offset of the target object and the mouse object in world space _vec3offset = _trans.position-selfcamer.screentoworldpoint (_vec3mousescreenspace); Left mouse button pressed while (Input.getmousebutton (0)) {//wait for fixed update yield return new waitforfixedupdate (); }} IEnumerator OnMouseUp () {Debug.Log (_trans.localposition+ "Mouse message *****************************onmouseup:" + Original_trans.localposition); if (_trans.localposition.z-original_trans.localposition.z >= 0.7) && Mathf.abs (_trans.localposition.x- Original_trans.localposition.x) <= 0.5) {Debug.Log ("onmouseup=============="); }//wait for fixed update yield return new waitforfixedupdate (); } IEnumerator Onmousedrag () {Debug.Log ("mouse Message *****************************onmousedrag"); Store the mouse's screen space coordinates (z-values use the target object's screen space coordinates) _vec3mousescreenspace = new Vector3 (input.mouseposition.x, INPUT.MOUSEPOSITION.Y, _ VEC3TARGETSCREENSPACE.Z); Converts the screen space coordinates of the mouse to World space coordinates (z-values use the screen space coordinates of the target object), plus offsets as the target object's world space coordinates _vec3targetworldspace = Selfcamer.screentoworldpoin T (_vec3mousescreenspace) + _vec3offset; Update the target object's world space coordinates _trans.position = _vec3targetworldspace; Wait for fixed update yield return new waitforfixedupdate (); }//update is called once per framevoid update () {}}
Third, the object pool:
Because in the combat scene, we need to frequently create aircraft objects and bullet objects as well as various effects, if you do not use the object pool, so frequent object creation and destruction operations will inevitably lead to high memory consumption, on some mobile devices also have a serious device fever and flash phenomenon, in order to avoid such things happen, We need to create a pool of objects in a battle scenario, where objects are destroyed and placed in the object pool, and the next time you use the object directly from the pool to reuse, and then create new objects when the object is not enough, which can greatly improve the performance of the game. Here I use third-party plug-in poolmanager to design my own object pool:
1. Get the Object pool:
Private Spawnpool Mactors_pool;
Mactors_pool = poolmanager.pools["Actorsandbullets"];
2. How to get objects:
Transform Bulletprefab = mactors_pool.prefabs["Bullet"];
Transform bullet = Mactors_pool.spawn (Bulletprefab);
3. How to Destroy objects:
Mactors_pool.despawn (bullet);
Unity Learning note 12--Fighter Fight module