0

这是我的播放器代码

    public Rigidbody rb;
    public MachineGun MG1;
    public WeaponRays wr;
    Vector3 Realpos = Vector3.one;
    Quaternion Realrot = Quaternion.identity;
    public Animator anim;
    // Use this for initialization
    void OnEnable() {
        anim = GetComponent<Animator>();
        wr = GetComponent<WeaponRays> ();
        MG1 = GetComponentInChildren<MachineGun> ();

        if (photonView.isMine) {
            MG1.enabled = true;
            cym = GetComponentInChildren<CameraYmovement> ();
            cym.enabled = true;
            myCam.SetActive (true);
            rb = GetComponent<Rigidbody> ();
        } else if (!photonView.isMine) {
            rb = GetComponent<Rigidbody> ();
            Destroy (myCam);
            cym = GetComponentInChildren<CameraYmovement> ();
            Destroy (cym);
        }
        Debug.Log ("is true");
    }
    public void Update(){
        if (photonView.isMine) {

        }else{
            transform.position = Vector3.Lerp(transform.position, Realpos, 0.1f);
            transform.rotation = Quaternion.Lerp (transform.rotation, Realrot, 0.1f);
        }
    }
    public void OnPhotonSerializeView (PhotonStream Stream,PhotonMessageInfo info){
        if (Stream.isWriting) {
            Stream.SendNext (transform.position);
            Stream.SendNext (transform.rotation);
            Stream.SendNext (rb.velocity);
            Stream.SendNext (anim.GetBool("Walking"));
            Stream.SendNext (anim.GetBool("Jumping"));
            Stream.SendNext (anim.GetBool ("MACHINEGUN"));
        }else{
            Realpos = (Vector3)Stream.ReceiveNext ();
            Realrot = (Quaternion)Stream.ReceiveNext ();
            rb.velocity = (Vector3)Stream.ReceiveNext ();
            anim.SetBool ("Walking", (bool)Stream.ReceiveNext ());
            anim.SetBool ("Jumping",(bool)Stream.ReceiveNext());
            anim.SetBool ("MACHINEGUN", (bool)Stream.ReceiveNext ());
        }
    }
}

基本上我只想了解 rpc 是如何工作的,以及我如何才能买一顶帽子,比如只买 rpc 自己。

这是我的 hp 损坏代码

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class WeaponRays : Photon.MonoBehaviour {
    public float Hp;
    public Text HealthTxt;
    public MachineGun Mg;   
    // Use this for initialization
    void Start () {
        Hp = 100f;
        Mg = GetComponentInChildren<MachineGun> ();
        HealthTxt = GameObject.Find ("HealthTxt").GetComponent<Text> ();
    }

    // Update is called once per frame
    void Update () {
        if(Input.GetButtonDown("Fire1") && photonView.isMine){
            Debug.Log ("Shoot");
        RaycastHit hit;
            if (Physics.Raycast (Camera.main.transform.position, Camera.main.transform.forward, out hit, Mathf.Infinity)) {
                if (hit.collider.tag == "Player") {
                    var p = hit.collider.GetComponent<PhotonView> ();
                    p.RPC ("hit", PhotonTargets.Others, 10);
                } else {

                }
            }
        }
    }
    [PunRPC]
    void hit(int Dam){
        Hp += -Dam;
        HealthTxt.text = "HP:" + Hp;
    }
}

tldr 我怎样才能让我的玩家在点击功能(有效)上显示他的粒子系统并让它同步。我只需要帮助理解工作流程。它是如此令人困惑。

4

0 回答 0