这是我的播放器代码
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如何让我的玩家在点击功能上显示他的粒子系统(有效)并让它同步。一世 只需要帮助了解工作流程。它如此令人困惑。