C# 用于统一独立同步的光子
这是我的播放器代码C# 用于统一独立同步的光子,c#,unity3d,unityscript,photon,C#,Unity3d,Unityscript,Photon,这是我的播放器代码 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()
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 ());
}
}
}
公共刚体rb;
公共机构MG1;
公共武器;
Vector3 Realpos=Vector3.1;
四元数Realrot=四元数.identity;
公共动画;
//用于初始化
void OnEnable(){
anim=GetComponent();
wr=GetComponent();
MG1=getComponentChildren();
if(photonView.isMine){
MG1.enabled=true;
cym=getComponentChildren();
cym.enabled=true;
myCam.SetActive(true);
rb=GetComponent();
}如果(!photonView.isMine)出现其他情况{
rb=GetComponent();
销毁(myCam);
cym=getComponentChildren();
破坏(cym);
}
Debug.Log(“为真”);
}
公共无效更新(){
if(photonView.isMine){
}否则{
transform.position=Vector3.Lerp(transform.position,Realpos,0.1f);
transform.rotation=Quaternion.Lerp(transform.rotation,Realrot,0.1f);
}
}
在PhotonSerializeView(PhotonStream流、PhotonMessageInfo信息)上公开作废{
if(Stream.isWriting){
Stream.SendNext(transform.position);
Stream.SendNext(transform.rotation);
Stream.SendNext(rb.velocity);
Stream.SendNext(anim.GetBool(“行走”);
Stream.SendNext(anim.GetBool(“跳跃”);
Stream.SendNext(anim.GetBool(“MACHINEGUN”);
}否则{
Realpos=(Vector3)Stream.ReceiveNext();
Realrot=(四元数)Stream.ReceiveNext();
rb.velocity=(Vector3)Stream.ReceiveNext();
anim.SetBool(“Walking”,(bool)Stream.ReceiveNext());
anim.SetBool(“跳跃”,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;
}
}
使用UnityEngine;
使用系统集合;
使用UnityEngine.UI;
公共级武器射线:光子.单粒子行为{
公众持股;
公共文本;
公共机构;
//用于初始化
无效开始(){
Hp=100f;
Mg=getComponentChildren();
HealthTxt=GameObject.Find(“HealthTxt”).GetComponent();
}
//每帧调用一次更新
无效更新(){
if(Input.GetButtonDown(“Fire1”)和&photonView.isMine){
Debug.Log(“Shoot”);
雷卡斯特击中;
if(Physics.Raycast(Camera.main.transform.position,Camera.main.transform.forward,out hit,Mathf.Infinity)){
如果(hit.collider.tag==“玩家”){
var p=hit.collider.GetComponent();
p、 RPC(“击中”,摄影目标。其他,10);
}否则{
}
}
}
}
[扑克牌]
无效命中(内部大坝){
Hp+=-大坝;
HealthTxt.text=“HP:+HP;
}
}
tldr如何让我的播放器在hit函数上显示他的粒子系统(有效)并使其同步。我
只是需要了解工作流程的帮助。这太令人困惑了 我甚至不知道要启用/禁用哪些脚本。如何详细描述PhotoNRPC中的工作流程:Tutuorial on PUN包括RPC: