【问题标题】:Display a message to a specific player in a networked game using Photon Unity Networking使用 Photon Unity Networking 向网络游戏中的特定玩家显示消息
【发布时间】:2014-11-14 19:10:23
【问题描述】:

在进入对象的触发区域时,会向玩家显示一条消息(通过标签找到)。如果玩家随后按下拾取按钮,该物品将被添加到他们的库存中。它在单人游戏中运行良好。

当我使用 PUN(光子网络)时,它会向所有玩家显示它(因为所有玩家的脚本都检测到事件)并且所有玩家都可以拾取该物品。我该如何解决这个问题?

我相信修复这篇文章将使我了解如何修复其他所有内容:

void OnTriggerEnter(Collider col)
{
    if (col.gameObject.tag == "Player")
    {
        displayMessage = true;
    }
}
void OnTriggerExit(Collider col)
{
    if (col.gameObject.tag == "Player")
    {
        displayMessage = false;
    }
}
bool stop = false;

void OnGUI()
{
    if (displayMessage)
    {

        if (GameObject.FindGameObjectWithTag("UInventory").GetComponent<UInventory>().inventoryMode == "Weight")
        {
            GUI.Label(new Rect((Screen.width/2)-200, (Screen.height/2)-30, 200, 45), "Press " + pickUpItem.ToString() + " To Take " + itemName + "(" + itemWeight + "kg)");
        }
        else
        {
            GUI.Label(new Rect((Screen.width/2)-200, (Screen.height/2)-30, 200, 45), "Press " + pickUpItem.ToString() + " To Take " + itemName);
        }
    }
}

【问题讨论】:

    标签: networking unity3d photon


    【解决方案1】:

    仅当客户端拥有网络对象时才应执行触发代码。使用对象的“PhotonView”组件的“isMine”属性来检查是否为真。

    【讨论】:

      猜你喜欢
      • 2015-10-11
      • 1970-01-01
      • 2022-01-14
      • 2020-10-08
      • 2016-09-29
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 2019-11-10
      相关资源
      最近更新 更多