Ejemplo n.º 1
0
    IEnumerator GetBlood(int viewID, int crtBlood, int maxBlood, string name)
    {
        while (GameObject.Find("BloodCanvas") == null)
        {
            yield return(0);
        }

        Debug.Log("收到" + viewID);
        //实例化血条
        GameObject go = Instantiate(Resources.Load <GameObject>("Blood"));

        //查找所有玩家
        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
        //根据viewID查找目标玩家
        for (int i = 0; i < players.Length; i++)
        {
            //找到目标玩家
            if (players[i].GetComponent <PhotonView>().ViewID == viewID)
            {
                //设置血条跟随的玩家
                go.GetComponent <BloodBar>().player            = players[i].transform;
                players[i].GetComponent <PlayerBlood>().bBarGo = go;
                //查找画布
                canvas = GameObject.Find("BloodCanvas");
                //把血条放在画布下
                go.transform.SetParent(canvas.transform);
                BloodBar bBar = go.GetComponent <BloodBar>();
                bBar.SetMaxBlood(maxBlood);
                bBar.SetBlood(crtBlood);
                bBar.SetName(name);
                bBar.selfId = viewID;
                players[i].GetComponent <PlayerBlood>().bloodValue = maxBlood;
                break;
            }
        }

        //实例化血条
        // bloodBarGo = Instantiate(Resources.Load<GameObject>("Blood"));
        //bloodBarGo = PhotonNetwork.Instantiate("Blood", Vector3.zero, Quaternion.identity);


        //pv.RPC("SetBloodBar",RpcTarget.AllBufferedViaServer, bloodBarGo.GetComponent<PhotonView>().ViewID);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// 设置玩家名字
 /// </summary>
 /// <param name="name">名字</param>
 public void SetPlayerName(string name)
 {
     Debug.Log(bloodBar + "BloodBar");
     bloodBar.SetName(name);
 }