Beispiel #1
0
    private void Update()
    {
        if (this.isServer == false)
        {
            return;
        }
        //Debug.Log("当前在线的坦克的数量为:" + this.manage.numPlayers);
        if (this.tankNumber != this.manage.numPlayers)
        {
            //  说明有人连接上或有人退出了。
            if (this.tankNumber < this.manage.numPlayers)
            {
                //  说明有人连接上了。
                //  然后同步一下系统坦克的血量。
                //  Debug.Log("加入了一辆坦克");
                EnemyTankHealth enemyTankHealth = GameObject.FindGameObjectWithTag("EnemyTank").GetComponent <EnemyTankHealth>();
                enemyTankHealth.RpcOnChangeHealth(enemyTankHealth.currentHealth / enemyTankHealth.healthTotal);
                this.tankNumber++;

                //  接下来让让新加入的坦克同步一下当前坦克的信息。比如血量
                GameObject[] objs = GameObject.FindGameObjectsWithTag("Tank"); //  在服务器端获得当前所有的坦克
                for (int i = 0; i < objs.Length - 1; i++)                      //  最后一辆坦克就不用讲他的信息发送到各个客户端了,因为他一进来的时候已经同步了。

                //  Debug.Log("同步坦克信息");
                //  然后在单个获取其身上的生命组件。然后在发送给各个客户端。
                {
                    Tank_Health tank_Health = objs[i].GetComponent <Tank_Health>();

                    tank_Health.RpcSyncHealth(tank_Health.currentHealth / tank_Health.healthTotal, tank_Health.transform.localScale);
                    //   Debug.Log("坦克信息:" + tank_Health.currentHealth / tank_Health.healthTotal);
                }
            }
            else
            {
                //  说明有人退出了。

                this.tankNumber--;
            }
        }

        if (isUpdateColor)    //  说明有新的坦克加入,并且已经在服务器端同步了该颜色,那么现在应该同步到各个客户端了。
        //  Debug.Log("更新坦克的颜色。");
        {
            GameObject[] objs = GameObject.FindGameObjectsWithTag("Tank");  //  在服务器端获得当前所有的坦克

            for (int i = 0; i < objs.Length; i++)
            {  //  同步坦克的颜色,因为是随机的颜色,所以没加入一个坦克,都要同步一次。
                TankInfomation trans = objs[i].GetComponent <TankInfomation>();
                trans.RpcTankColor(trans.c.r, trans.c.g, trans.c.b);
            }

            isUpdateColor = false;  //  同步完颜色之后将标志设为false。
        }
    }
Beispiel #2
0
    public void Start()
    {
        this.firePosition    = this.transform.Find("TankRenderers/TankTurret/firePosition").GetComponent <Transform>();
        this.tankInformation = this.GetComponent <TankInfomation>();
        this.buller_Scale    = 1f;
        if (this.isLocalPlayer == true)
        {
            //  这个主要是要控制坦克joy来动态的给属性firingBullet赋值,因为会同时存在多个坦克,使得joy不知道该是哪个坦克身上的脚本。
            this.joy = GameObject.Find("Canvas").transform.Find("YaoGan_ControllFaShe/Joy").GetComponent <Joy>();
            this.joy.GetComponent <Joy>().firingBullet = this;
        }

        Network.sendRate = 60;
    }
Beispiel #3
0
    public GameObject ima;                 //  测试。

    private void Start()
    {
        this.tankInformation = this.GetComponent <TankInfomation>();
        this.healthTotal     = this.tankInformation.total_Health;
        this.currentHealth   = this.healthTotal;
        this.slider.enabled  = false;
        if (this.isLocalPlayer == true)
        {
            //  如果是本地的用户。

            //  当tank连接上客户端的时候,需要先同步一下系统坦克的血量。

            //Debug.Log("asdasd");  //  将自身的属性赋值。
            this.screenShotImage = GameObject.Find("Canvas").transform.Find("GameOverPanel/Image").GetComponent <Image>();
            this.gameOverPanel   = GameObject.Find("Canvas").transform.Find("GameOverPanel").gameObject;
            this.ima             = GameObject.Find("Canvas").transform.Find("Image").gameObject;
        }
    }
Beispiel #4
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 #5
0
    public void Update_UI()
    {
        this.tanks = GameObject.FindGameObjectsWithTag("Tank");

        int count_ = 0;

        this.tankInformations = new TankInfomation[this.tanks.Length];

        //  挨个获取每个坦克身上的tankInformation组件。
        foreach (GameObject obj in tanks)
        {
            this.tankInformations[count_++] = obj.GetComponent <TankInfomation>();

            //if (this.tankInformations[count_++].isLocalPlayer == true) {
            //    //  如果该坦克是本地的坦克。
            //    this.tank_Self = this.tankInformations[count_ - 1];

            //}
        }



        //  冒泡排序进行排序。
        int length = this.tankInformations.Length;

        for (int i = 0; i < length - 1; i++)
        {
            for (int j = 0; j < length - i - 1; j++)
            {
                if (this.tankInformations[j].grade < this.tankInformations[j + 1].grade)
                {
                    TankInfomation temp = this.tankInformations[j];
                    this.tankInformations[j]     = this.tankInformations[j + 1];
                    this.tankInformations[j + 1] = temp;
                }
            }
        }

        int k = 0;

        for (k = 0; k < length; k++)
        {
            //  如果找到了本地的排名,那么跳出,下标+1即是排名。
            if (this.tank_Self == this.tankInformations[k])
            {
                break;
            }
        }

        //  先把本地的坦克的得分信息显示上去。
        this.self_Ranking.transform.parent.gameObject.SetActive(true);
        this.self_Ranking.text = (k + 1) + ".";  //  显示排名。
        //  显示分数。
        if (this.tank_Self != null)
        {
            this.self_Information.text = this.tank_Self.tankName + "   " + this.tank_Self.grade + "";
        }

        //  下面开始更新排名ui。

        if (length < 5)
        {  //  如果当前的在线人数不够五个。
            for (int i = 0; i < length; i++)
            {
                this.grades[i].transform.parent.gameObject.SetActive(true);
                this.grades[i].text = this.tankInformations[i].tankName + "   " + this.tankInformations[i].grade + "";
            }
            for (int i = length; i < 5; i++)
            {  //  将剩下的没有用到的ui隐藏。
                this.grades[i].transform.parent.gameObject.SetActive(false);
            }

            //switch (length) {

            //    case 1:  //  如果是一个人在线。
            //        //  将排名组件激活。
            //        this.first.transform.parent.gameObject.SetActive(true);
            //        this.first.text = this.tankInformations[0].tankName + this.tankInformations[0].grade + "";
            //        break;
            //    case 2:  //  如果是两个人在线。
            //        //  将排名组件激活。
            //        this.first.transform.parent.gameObject.SetActive(true);
            //        this.first.text = this.tankInformations[0].tankName + this.tankInformations[0].grade + "";
            //        this.second.transform.parent.gameObject.SetActive(true);
            //        this.second.text = this.tankInformations[1].tankName + this.tankInformations[1].grade + "";
            //        break;
            //    case 3:  //  如果是三个人在线。
            //        //  将排名组件激活。
            //        this.first.transform.parent.gameObject.SetActive(true);
            //        this.first.text = this.tankInformations[0].tankName + this.tankInformations[0].grade + "";
            //        this.second.transform.parent.gameObject.SetActive(true);
            //        this.second.text = this.tankInformations[1].tankName + this.tankInformations[1].grade + "";
            //        this.third.transform.parent.gameObject.SetActive(true);
            //        this.third.text = this.tankInformations[2].tankName + this.tankInformations[2].grade + "";
            //        break;
            //    case 4:  //  如果是四个人在线。
            //        //  将排名组件激活。
            //        this.first.transform.parent.gameObject.SetActive(true);
            //        this.first.text = this.tankInformations[0].tankName + this.tankInformations[0].grade + "";
            //        this.second.transform.parent.gameObject.SetActive(true);
            //        this.second.text = this.tankInformations[1].tankName + this.tankInformations[1].grade + "";
            //        this.third.transform.parent.gameObject.SetActive(true);
            //        this.third.text = this.tankInformations[2].tankName + this.tankInformations[2].grade + "";
            //        this.tra
            //        break;
            //    case 1:  //  如果是一个人在线。
            //        //  将排名组件激活。
            //        this.first.transform.parent.gameObject.SetActive(true);
            //        this.first.text = this.tankInformations[0].tankName + this.tankInformations[0].grade + "";
            //        break;


            //}
        }
        else    //  如果当前的人数大于5个人。

        {
            for (int i = 0; i < 5; i++)
            {
                this.grades[i].transform.parent.gameObject.SetActive(true);
                this.grades[i].text = this.tankInformations[i].tankName + "   " + this.tankInformations[i].grade + "";
            }
        }
    }
Beispiel #6
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);
    }