实例化的预制比例尺未在客户端上正确显示 [英] Instantiated prefab scale is not displayed correctly on client

查看:95
本文介绍了实例化的预制比例尺未在客户端上正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以动画预制件为代表的爆炸.当用户单击UI按钮时,将实例化预制件.在客户端或主机上单击该按钮时,预制件将设置为Vector3(0.1,0.1,1)的本地比例,并在主机上正确显示,但在客户端上为原始比例.

I have an explosion represented by a animated prefab. The prefab is instantiated when the user clicks a UI button. When the button is clicked on the client or the host, the prefab is set to localscale of Vector3(0.1,0.1,1) and is displayed correctly on the host, but at orginal scale on the client.

我有一个文本框,显示客户端和主机上的比例,它们匹配,但是在主机(正确显示)和客户端(错误显示)上,预制件的显示有所不同.再次,客户端用户可以单击按钮,或者主机可以单击按钮,在两种情况下,主机上的显示都是正确的,但客户端上的显示却不正确.

I have a text box showing the scale on both the client and host, which match, but the display of the prefab is different on the host (displayed correctly) and client (displayed incorrectly). Again, the client user can click the button or the host can click the button, and in both cases the display is correct on the host, but not on the client.

有人猜测为什么我不能让客户端正确显示.似乎在客户端上可以使用本地比例0.1,0.1,1,因为我可以在文本框中显示它,但是预制件显示得更大.

Any guesses as to why I can't get the client to display correctly. It appears that the localscale of 0.1,0.1,1 is available on the client as I can show it in a text box, but the prefab is displayed much larger.

这是实例化代码.让我知道其他有助于诊断的信息.

This is the instantiation code. Let me know of any other info that would help to diagnose.

go = Instantiate(shockwave, this.transform, false);
NetworkServer.Spawn(go);

更新

这是我根据Lotan的评论更新的代码.请注意,我先调用createshockwave,然后再调用Cmdcreateshockwave,因为我无法从UI按钮调用Command.

This is my updated code based on Lotan's comments. Note that I am calling createshockwave first, which then calls Cmdcreateshockwave because I am not able to call a Command from the UI button.

public void createshockwave()
{
    if(!isLocalPlayer)
    { return; }

    Cmdcreateshockwave();
}

[Command]
public void Cmdcreateshockwave()
{

    //note that this line parents shockwave. The updated instantiation code below does not parent shockwave.
    //go = Instantiate(shockwave, this.transform, false);

    GameObject go = Instantiate(shockwave, this.transform.position, Quaternion.identity) as GameObject;

    NetworkServer.Spawn(go);

    go.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
...
}

现在,实例化预制件的大小在客户端和主机上都是相同的原始比例.将区域设置比例更改为其他大小不会产生任何效果.

Now, the size of the instantiated prefab is the same original scale on both the client and host. Changing the locale scale to other sizes doesn't have any effect.

更新 该问题似乎与预制件上的动画师有关.我删除了动画器,该动画器可缩放预制件,并且缩放器现在与客户端和主机上的父代匹配.看起来我将不得不在更新功能中手动增加localscale,而不是使用动画器.

UPDATE The issue appears to be related to an animator on the prefab. I removed the animator, which scales the prefab, and the scale now matches the parent on both the client and host. Looks like I'll have to manually increase localscale in the update function rather than using an animator.

推荐答案

  • NetworkServer.Spawn应该从[Command]函数
  • 调用

    • NetworkServer.Spawn should be called from a [Command] function
    • 赞:

      [Command]
      private void CmdSpawnStuff()
      {
          GameObject instance = Instantiate(prefab, 
                                            coords, 
                                            Quaternion.identity) as GameObject;
          NetworkServer.Spawn(instance);
      }
      

      • NetworkServer.Spawn,生成游戏对象的默认副本,因此,如果您在此处更改任何属性,将不会发送给客户端,因此请在生成后进行更改并进行同步.
        • NetworkServer.Spawn, spawns a default copy of the gameObject, so if you change any properties here, will not be sent to the client, so make the changes AFTER the spawn, and synchronize.
        • 希望有帮助!

          这篇关于实例化的预制比例尺未在客户端上正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆