- Home /
Question by
ozeol · Apr 26, 2021 at 08:55 PM ·
photonscript errorscriptingproblem
How can I instantiate a transform on Photon Network?
I am trying to run an animated prefab through Photon. In the tutorial this (non-animated) game object was passed through
void SpawnUnits ()
{
for(int x = 0; x < unitsToSpawn.Length; ++x)
{
GameObject unit = PhotonNetwork.Instantiate(unitsToSpawn[x], spawnPoints[x].position,
Quaternion.identity);
unit.GetPhotonView().RPC("Initialize", RpcTarget.Others, false);
unit.GetPhotonView().RPC("Initialize", photonPlayer, true);
}
}
The type of prefab I want to use however needs Transform (see below) which gives me the error: "Cannot implicitly convert type 'UnityEngine.GameObject' to 'UnitEngine.Transform'
for (int x = 0; x < pfCharacterBattle.Length; ++x)
{
Transform characterTransform = PhotonNetwork.Instantiate(pfCharacterBattle[x],
GetPosition(lanePosition1), Quaternion.identity);
CharacterBattle characterBattle = characterTransform.GetComponent<CharacterBattle>();
characterBattle.Setup(characterType, lanePosition1, GetPosition(lanePosition1), stats);
instance.characterBattleList.Add(characterBattle);
characterBattle.GetPhotonView().RPC("Initialize", RpcTarget.Others, false);
characterBattle.GetPhotonView().RPC("Initialize", photonPlayer, true);
}
Comment
Answer by suIly · Apr 27, 2021 at 05:12 PM
You cannot Instantiate a Transform component through Photon. Can you instead change the variable to a GameObject instead?