Beispiel #1
0
    public void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Tank")
        {
            //Debug.Log("tankechidiao");
            Destroy(this.gameObject);

            //  经验, 攻击, 防御, 射程, 速度, 无敌
            int random = Random.Range(0, 6);  //  生成0 - 5
            //int random = 0;
            TankInfomation tankInformation = other.GetComponent <TankInfomation>();

            switch (random)
            {
            case 0:
                tankInformation.GetExperiencee(200f);
                tankInformation.RpcGetExperiencee(200f);
                tankInformation.grade += 100;
                break;

            case 1:
                tankInformation.AddAtk(10f);
                break;

            case 2:
                tankInformation.AddDef(8f);
                break;

            case 3:
                tankInformation.AddRange(10f);
                break;

            case 4:
                tankInformation.AddSpeed(0.4f);
                break;

            case 5:
                tankInformation.AddShield();
                break;
            }

            GameObject.Find("ControlPlane").GetComponent <ControlPlane>().isHavaGood = false;  //  将物品吃完之后在将其重新赋值。
        }
    }
Beispiel #2
0
    //private void Update()
    //{

    //    if (this.isLocalPlayer) {

    //        if (Input.GetKeyDown(KeyCode.Space)) {

    //            Debug.Log("退出服务器");
    //            GameObject.Find("UnetManage").GetComponent<NetworkManager>().StopClient();

    //        }


    //    }

    //}

    public void TakeDamage(float dama, int number)
    {
        // Debug.Log("123");
        //Debug.Log("tank:" + number);
        dama = dama - this.tankInformation.defense;   //  最后的伤害等于传过来的伤害减去当前坦克的防御。
        if (dama < 0)
        {
            dama = 0;
        }
        if (this.currentHealth <= 0)
        {
            return;
        }
        this.currentHealth -= dama;
        if (this.currentHealth <= 0)
        {
            this.tankInformation.current_Health = 0;
        }
        else
        {
            this.tankInformation.current_Health = this.currentHealth;
        }
        if (this.currentHealth <= 0)
        {
            //  说明已经死亡。

            if (number != 100)    //  说明不是系统坦克打死的,那么给坦克加经验。
            {
                GameObject[] tanks = GameObject.FindGameObjectsWithTag("Tank");
                for (int i = 0; i < tanks.Length; i++)
                {
                    TankInfomation trans = tanks[i].GetComponent <TankInfomation>();

                    if (trans.tank_Number == number)    //  找到了该坦克

                    // Debug.Log("gaitank:" + number);

                    {
                        trans.grade += 50;
                        trans.GetExperiencee(100);
                        trans.RpcGetExperiencee(100);
                        break;
                    }
                }
            }


            this.currentHealth = 0;
            this.tankInformation.current_Health = 0;
            //  实例化爆照效果。
            GameObject.Instantiate(this.tankExplosionPre, this.transform.position, this.transform.rotation);
            //  播放坦克爆炸音效。
            AudioSource.PlayClipAtPoint(this.tankExplosionAudio, this.transform.position);
            GameObject.Destroy(this.gameObject);
            RpcTankBoom();
            //TankDead();
        }
        this.slider.value = this.currentHealth / this.healthTotal;

        //if(this.isLocalPlayer == true)
        this.tankInformation.Update_UI();      //  更新ui;
        RpcOnChangeHealth(this.slider.value, this.currentHealth);
    }