Ejemplo n.º 1
0
    private void Penetrate()
    {
        P_tank.BeAttacked(SDamage * Random.Range(90, 110) / 100, attacker);
        int        P = 0;
        GameObject LastPiece;

        switch (ShellType)
        {
        case shelltype.AP:
            P = 4;
            break;

        case shelltype.APCR:
            P = 3;
            break;
        }
        for (int i = 0; i < P; i++)
        {
            LastPiece = Instantiate(gameObject, Ray_startPos, transform.rotation);
            Bullet lastpiece = LastPiece.GetComponent <Bullet>();
            lastpiece.IsFresh = false;
            lastpiece.Speed   = 6f;
            Destroy(LastPiece.GetComponent <MeshRenderer>());
            LastPiece.transform.Rotate(new Vector3(Random.Range(0f, 45f), Random.Range(0f, 45f), 0));
        }
    }
Ejemplo n.º 2
0
    //碰撞
    private void OnCollisionEnter(Collision collisionInfo)
    {
        //打到自身
        if (collisionInfo.gameObject == attackTank)
        {
            return;
        }
        //爆炸效果
        GameObject explodeObj = (GameObject)Instantiate(explode, transform.position, transform.rotation);
        //爆炸音效
        AudioSource audioSource = explodeObj.AddComponent <AudioSource>();

        audioSource.spatialBlend = 1;
        audioSource.PlayOneShot(explodeClip);
        //摧毁自身
        Destroy(gameObject);
        //击中坦克
        Tank tank = collisionInfo.gameObject.GetComponent <Tank>();

        if (tank != null)
        {
            float att = GetAtt();
            tank.BeAttacked(att, attackTank);
        }
    }
Ejemplo n.º 3
0
    void OnCollisionEnter(Collision collisionInfo)
    {
        if (collisionInfo.gameObject == attackTank)
        {
            return;
        }
        Explode();

        Tank tank = collisionInfo.gameObject.GetComponent <Tank>();

        if (tank != null)
        {
            float att = GetAtt();
            tank.BeAttacked(att, attackTank);
        }
    }
Ejemplo n.º 4
0
    void OnCollisionEnter(Collision collisionInfo)
    {
        if (collisionInfo.gameObject == attackTank)
        {
            return;
        }
        Instantiate(explode, transform.position, transform.rotation);
        Destroy(gameObject);
        Tank tank = collisionInfo.gameObject.GetComponent <Tank> ();

        if (tank != null)
        {
            float att = GetAtt();
            tank.BeAttacked(att, attackTank);
        }
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        //假如得知遊戲已經輪掉就拒絕不做接下來的程式碼
        if (gameManager.instance.IsLose)
        {
            return;
        }

        //當按下滑鼠左鍵(GetMouseButtonDown(0)是左鍵也是手機點擊
        if (Input.GetMouseButtonDown(0))
        {
            //因為發射子彈,所以需要有開火聲
            FireAudioSource.Play();

            //求得手機晝面中心點
            Vector3 CenterScreenPoint = new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0);
            //把手機晝面中心點轉為世界坐標
            Vector3 CenterGamePoint = Camera.main.ScreenToWorldPoint(CenterScreenPoint);

            //初設射線
            Ray ray = new Ray(CenterGamePoint, Camera.main.transform.forward * 100);
            //在Scene裡畫出一條紅線,好讓我們看到射線射在哪
            Debug.DrawLine(CenterGamePoint, CenterGamePoint + Camera.main.transform.forward * 100, Color.red);

            RaycastHit hit;
            //射線判定,結果會輸出在hit
            if (Physics.Raycast(ray, out hit, 100))
            {
                //試在射線結果中找出坦克特徵
                Tank enemy = hit.collider.GetComponent <Tank>();
                //確定射線結果真的為坦克
                if (enemy)
                {
                    //輸出100點傷害,這肯定必死了
                    enemy.BeAttacked(100);
                    //確定對方真的死透
                    if (enemy.isDead)
                    {
                        //總得分加一分
                        gameManager.instance.Score++;
                        //讓UI更新得分
                        ScoreUI.instance.UpdateText(gameManager.instance.Score);
                    }
                }
            }
        }
    }
Ejemplo n.º 6
0
    private void OnCollisionEnter(Collision collision)
    {
        //Debug.Log("Boom!!");
        GameObject  explodeObj   = Instantiate(explode, transform.position, Quaternion.identity);
        AudioSource explodeAudio = explodeObj.AddComponent <AudioSource>();

        explodeAudio.spatialBlend = 1;
        explodeAudio.PlayOneShot(explodeClip, 2.0f);

        if (collision.gameObject.tag == "Tank")
        {
            Tank tank = collision.gameObject.GetComponent <Tank>();
            if (tank != null)
            {
                float att = GetAtt();
                tank.BeAttacked(att, attackTank);
            }
        }


        Destroy(gameObject);
    }
Ejemplo n.º 7
0
    private void FixedUpdate()
    {
        //自身移动
        transform.transform.position += transform.forward * Speed * Time.fixedDeltaTime;

        //碰撞判定
        float      length    = (transform.position - Ray_startPos).magnitude; //射线的长度
        Vector3    direction = transform.position - Ray_startPos;             //方向
        RaycastHit hitinfo;
        bool       isCollider = Physics.Raycast(Ray_startPos, direction, out hitinfo, length);

        Ray_startPos = hitinfo.point;
        if (isCollider)
        {
            //确定被击者
            atted    = hitinfo.collider.gameObject;
            property = atted.GetComponent <Property>();//获取被击者的Property脚本


            switch (property.type)
            {
            case Property.TYPE.wall: //打到墙的场合
                if (!IsFresh)        //
                {
                    return;
                }
                float HP = property.HP;
                if (Penetration >= HP)
                {
                    Penetration -= 20;
                    Destroy(atted);
                }
                else
                {
                    property.BeAttacked(Penetration);
                    Destroy(gameObject);
                }
                break;

            case Property.TYPE.barriar:
                if (!IsFresh)
                {
                    return;
                }
                if (Penetration > 100)
                {
                    Destroy(atted);
                    Penetration -= 100;
                }
                else
                {
                    Destroy(gameObject);
                }
                break;

            case Property.TYPE.Armor:
                if (!IsFresh)
                {
                    if (IsFirst)
                    {
                        IsFirst = false;
                    }
                    else
                    {
                        Destroy(gameObject);
                    }
                    return;
                }
                attedParent = property.parent;                   //获取被击者本体信息
                P_tank      = attedParent.GetComponent <Tank>(); //获取被击者本体的Tank脚本
                #region 打中装甲模型

                //敌我判定
                if (P_tank.camp == attacker.GetComponent <Tank>().camp)
                {
                    print("命中友军");
                }
                float ArmorValue = property.ArmorValue;

                //跳弹计算
                AttedForward = atted.transform.forward;    //获取被击面的法向量

                AttedForward = Quaternion.AngleAxis(property.Angle_X, Vector3.right) * AttedForward;
                AttedForward = Quaternion.AngleAxis(property.Angle_Y, Vector3.up) * AttedForward;
                AttedForward = Quaternion.AngleAxis(property.Angle_Z, Vector3.forward) * AttedForward;
                Angle        = 180 - Mathf.Acos(Vector3.Dot(gameObject.transform.forward, AttedForward)) * Mathf.Rad2Deg; //计算入射角

                if (Angle > RicochetAngle && Caliber < 3 * ArmorValue)                                                    //满足跳弹条件

                {
                    //gameObject.transform.position = Ray_startPos;
                    //Vector3 newdir = Vector3.Reflect(gameObject.transform.forward, AttedForward);//计算反弹的方向
                    //transform.rotation = Quaternion.LookRotation(-newdir);

                    //Ricochet();
                    break;
                }

                if (IsFirst)                                 //穿透力浮动只计算一次
                {
                    Penetration *= Random.Range(0.9f, 1.1f); //进行10%的上下浮动计算
                }
                //转正效应
                N_CorrectionAngle = CorrectionAngle;

                //二倍转正增加机制
                if (Caliber >= 2 * ArmorValue)
                {
                    N_CorrectionAngle = 1.4f * CorrectionAngle * Caliber / ArmorValue;
                }

                //等效装甲计算
                if (Angle < N_CorrectionAngle)
                {
                    N_CorrectionAngle = Angle;    //防止出现0-90以外的角度
                }
                ArmorValue = ArmorValue / Mathf.Cos(Mathf.PI * (Angle - N_CorrectionAngle) / 180);
                if (Penetration >= ArmorValue)
                {
                    Penetrate();

                    Debug.Log("击穿");
                    IsFirst = false;
                    IsFresh = false;
                    Destroy(gameObject.GetComponent <MeshRenderer>());
                    Destroy(gameObject, 6f / Speed);
                }
                else
                {
                    Debug.Log("我们未能穿透");
                }
                Destroy(gameObject);
                break;

                #endregion
            case Property.TYPE.crew:
                attedParent = property.parent;                   //获取被击者本体信息
                P_tank      = attedParent.GetComponent <Tank>(); //获取被击者本体的Tank脚本
                if (!IsFresh)                                    //判断是否进入伤害计算阶段
                {
                    P_tank.BeAttacked(EDamage * Random.Range(90, 110) / 100, attacker);
                    Debug.Log(atted.name);
                }
                break;

            case Property.TYPE.parts:
                attedParent = property.parent;                   //获取被击者本体信息
                P_tank      = attedParent.GetComponent <Tank>(); //获取被击者本体的Tank脚本
                if (!IsFresh)
                {
                    P_tank.BeAttacked(EDamage * Random.Range(90, 110) / 100, attacker);
                    Debug.Log(atted.name);
                }
                break;

            case Property.TYPE.others:

                break;
            }
        }
        Ray_startPos = transform.position;
    }