我正在尝试实例化场景中已经存在的对象,以便我可以放大它并“放大”它,但是当我玩游戏并将鼠标悬停在一个对象上时,而不是显示放大的卡片,这出现错误:
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.
注意:我正在学习带镜像的 2D Unity Card 游戏教程 (2019.2.15f1),并且我使用的是不同版本的 Unity (2020.1.0f1)。
首先,我使用这个脚本将对象实例化到我的游戏中,它从不抛出任何错误。
[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");
}
}
当我稍后再次尝试实例化这些对象时,问题就出现了,这里:
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);
}