在我的项目中,我创建了一个“疯狂战斗”的-like游戏,但通过光子网络多人。我目前有一个问题是错误的客户“手+枪”是翻转的。
当客户1翻转他的角色时,他的手被局部翻转,客户2的手被局部翻转。
图片来源:https://imgur.com/a/NkP3KEF
我相信问题是这样的:在我的角色翻转逻辑中,我调用了一个将错误客户手翻过来的PunRPC。
主人公翻转功能:
void FixedUpdate()
{
if (!disableMove)
{
//if (!devTesting)
//{
if (photonView.isMine)
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if (facingRight == false && moveInput > 0)
{
photonView.RPC("Flip", PhotonTargets.AllBuffered);
photonView.RPC("Fliphand", PhotonTargets.AllBuffered); //FLIPS HAND+GUN
//Flip();
}
else if (facingRight == true && moveInput < 0)
{
photonView.RPC("Flip", PhotonTargets.AllBuffered);
photonView.RPC("Fliphand", PhotonTargets.AllBuffered); //FLIPS HAND+GUN
//Flip();
}
}
}上面的函数调用这两个PunRPC函数。
角色翻转:
[PunRPC]
void Flip()
{
facingRight = !facingRight; //toggle flipping
GetComponent<SpriteRenderer>().flipX = !facingRight;
}Hand flip (上面游戏对象的子对象):
[PunRPC]
void Fliphand()
{
child = GameObject.Find("Hand");
sight = GameObject.Find("Granny_warr_lasersight");
deagle = GameObject.Find("deagle_animation");
facingRight2 = !facingRight2;
child.GetComponent<SpriteRenderer>().flipY = !facingRight2;
sight.GetComponent<SpriteRenderer>().flipY = !facingRight2;
deagle.GetComponent<SpriteRenderer>().flipY = !facingRight2;
}我认为问题是因为两个客户端加入了房间,并且两个客户端都有名为"Hand“的子对象,等等。通过从客户端1调用此PunRPC,它翻转了客户端2屏幕上的”手“。
有人能帮我解决这个问题吗?我会尽量让它更清楚,如果需要,并提供更多的图片,如果要求。
注意:字符翻转在两个客户端上都工作得很好。
发布于 2020-01-31 00:50:29
多亏了Tomer Shahar提供的链接,我解决了这个问题!
[PunRPC]
void Fliphand()
{
//if (photonView.isMine)
//{
//child = GameObject.Find("Hand");
//sight = GameObject.Find("Granny_warr_lasersight");
//deagle = GameObject.Find("deagle_animation");
child = player.transform.Find("Hand").gameObject;
sight = child.transform.Find("Granny_warr_lasersight").gameObject;
deagle = child.transform.Find("deagle_animation").gameObject;
facingRight2 = !facingRight2;
child.GetComponent<SpriteRenderer>().flipY = !facingRight2;
sight.GetComponent<SpriteRenderer>().flipY = !facingRight2;
deagle.GetComponent<SpriteRenderer>().flipY = !facingRight2;
//}
}//禁用的代码是不适用于我的应用程序的旧代码。新的工作起来像个魔法师!
https://stackoverflow.com/questions/59989287
复制相似问题