簡體   English   中英

光子網絡實例化錯誤(Unity3d)

[英]Photon Networking Instantiate Error (Unity3d)

好的,所以我在Unity中制作了一個在線FPS,並且正在編寫該Photon Networking Script來連接和生成播放器的腳本,而我不斷遇到這兩個錯誤:

Assets/Resources/GameManager.cs(64,23): error CS1502: The best overloaded method match for `PhotonNetwork.Instantiate(string, UnityEngine.Vector3, UnityEngine.Quaternion, int)' has some invalid arguments

Assets/Resources/GameManager.cs(64,23): error CS1503: Argument `#1' cannot convert `UnityEngine.Transform' expression to type `string'

這是我的代碼中的錯誤所在:

    // When Connected [Photon Callback]
void OnJoinedRoom()
{
    PhotonNetwork.Instantiate(playerPrefab, transform.position, Quaternion.identity, 0);
}

//In Game: Disconnect from room.
void InGameGUI()
{
    if (GUILayout.Button("Leave Game"))
        PhotonNetwork.LeaveRoom();
}

}

我確實在頂部引用了Transform:

public Transform playerPrefab;

關於我做錯了什么以及如何解決的任何想法。 請幫忙!

PhotonNetwork.Instantiate需要一個string ,而不是Transform對象,因為它是第一個參數。 (我確實相信這是從前一段時間的Transform對象更改的)。 只需命名您要實例化的預制件(必須在Resources文件夾中)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM