困扰很多天的技能效果同步终于解决了,办法:
1.将技能创建数组,把预制件赋值给英雄技能数组;
2.技能添加碰撞事件;
3.在释放生成技能时用PunRPC,同步到所有客户端,这时所有的技能效果就可以同步了,这是非常关键一步,之前曾经用photonnetwork实例化技能,但是只是同步了部分效果,在碰撞逻辑处理上,这个办法很纠结,又想过用photonserilze传参数,发现也不靠谱,需要传的参数太多。
[PunRPC]
void Shootwave(int go,Vector3 hitposition, Vector3 position, Quaternion rotation, PhotonMessageInfo info)
{
GameObject go3 = effects[go];
GameObject newobj3 = new GameObject();
newobj3.transform.position = hitposition;
go3.GetComponent().Target = newobj3;
Instantiate(effects[go], position, rotation);
}
触发技能按钮事件:
case 3://冲击波技能
if (PlayerManager.LocalPlayerInstance.GetComponent().IsMine)
{
//转身newobj3
PlayerManager.LocalPlayerInstance.transform.LookAt(new Vector3(hitPoint.x, PlayerManager.LocalPlayerInstance.transform.position.y, hitPoint.z));
}
PlayerManager.LocalPlayerInstance.GetComponent().RPC(“Shootwave”, RpcTarget.AllViaServer, 3, new Vector3(hitPoint.x, PlayerManager.LocalPlayerInstance.transform.position.y, hitPoint.z), PlayerManager.LocalPlayerInstance.transform.position, Quaternion.identity);
PlayerManager.LocalPlayerInstance.GetComponent().CrossFade(“attack”);
PlayerManager.LocalPlayerInstance.GetComponent().animationsname = “attack”;
PlayerManager.LocalPlayerInstance.GetComponent().ismoving = false;
break;
4.在碰撞掉血的碰撞事件中要加hitcollider的photonview进行判断控制,防止反复掉血。
ok。
unity photon中技能效果网络同步
最新推荐文章于 2022-02-15 23:04:45 发布