如何转换 'GameObject to Custom Class'

How to convert 'GameObject to Custom Class'

我基本上是在尝试将离线游戏转换为在线游戏,游戏使用 VArmory 作为枪支系统,使用 Photon Network 作为在线解决方案。所以基本上我有一个正常的统一实例化功能,它似乎可以工作但是当我尝试光子网络的实例化功能时它没有。我该如何解决这个问题?

搜索过类似问题,但似乎找不到。

Bullet bullet = PhotonNetwork.Instantiate(bulletClone.name, transform.position, transform.rotation); // This is the code I am trying to use.

说 "Cannot implicitly convert type 'UnityEngine.GameObject' to 'VArmory.Bullet'"。

Bullet bullet = Instantiate(bulletClone, transform.position, transform.rotation); // Default code that was working.

基本上我是在尝试在网络上生成子弹。

好吧Unity的InstantiatereturnsT提供的prefab的类型。

PhotonNetwork.Instantiate returns a GameObject 所以你必须 "manually" 像往常一样使用 GetComponent 得到相应的组件

Bullet bullet = PhotonNetwork.Instantiate(bulletClone.name, transform.position, transform.rotation).GetComponent<Bullet>();