简体   繁体   English

无法实例化“场景对象”[Unity Mirror Multiplayer]

[英]Can't instantiate "scene object" [Unity Mirror Multiplayer]

I am trying to instantiate an object that already exists in the scene so that I can enlarge it and "zoom" in on it, but when I play the game and hover over an object, instead of showing the zoomed card, this error shows up:我正在尝试实例化场景中已经存在的 object,以便我可以放大它并“放大”它,但是当我在 object 上玩游戏和 hover 时,会显示此错误,而不是显示放大卡, :

Card1(Clone)(Clone) has already spawned. Don't call Instantiate for NetworkIdentities that were in the scene since the beginning (aka scene objects). Otherwise the client won't know which object to use for a SpawnSceneObject message.

NOTE: I am following a tutorial for a 2D Unity Card game with mirror (2019.2.15f1), and I am using a different version of Unity (2020.1.0f1).注意:我正在关注带有镜像 (2019.2.15f1) 的 2D Unity Card 游戏的教程,并且我使用的是不同版本的 Unity (2020.1.0f1)。

First, I am instantiating objects into my game with this script, which never throws any errors.首先,我使用这个脚本将对象实例化到我的游戏中,它从不抛出任何错误。

[Command]
public void CmdDealCards()
{
    for (int i = 0; i < 4; i++)
    {
        GameObject card = Instantiate(playerDeck[Random.Range(0, playerDeck.Count)], new Vector2(0, 0), Quaternion.identity);
        NetworkServer.Spawn(card, connectionToClient);
        RpcShowCard(card, "Dealt");
    }
}

The problem comes when I try to instantiate these objects again later, here:当我稍后尝试再次实例化这些对象时,问题就来了,这里:

public void OnHoverEnter()
{
    zoomCard = Instantiate(gameObject, new Vector2(Input.mousePosition.x, 540), Quaternion.identity);
    zoomCard.transform.SetParent(Canvas.transform, true);
    zoomCard.layer = LayerMask.NameToLayer("Zoom");

    RectTransform rect = zoomCard.GetComponent<RectTransform>();
    rect.sizeDelta = new Vector2(240, 354);
}

I know this is a really late answer, but I came across it while running into the same issue, and maybe in the future, someone will do the same as me, so:我知道这是一个很晚的答案,但是我在遇到同样的问题时遇到了它,也许将来有人会和我一样,所以:

What you've done is attached the wrong prefab to your CardZoom script in the Inspector.您所做的是将错误的预制件附加到 Inspector 中的 CardZoom 脚本中。 Image of Inspector with Zoom Card attached附有 Zoom Card 的 Inspector 图像

What I did, and presumably you also, was to attach Card1 here, which is where it was failing to duplicate the NetworkIdentity我所做的,大概你也是,是在这里附加 Card1,这是它无法复制 NetworkIdentity 的地方

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM