- Home /
Question by
RandomaaK · Sep 26, 2021 at 11:47 AM ·
multiplayerphoton
How to spawn 2 different player prefabs using Photon?
My problem
m currently working on my first multiplayer game. It's 1v1 duel, where each player should stay on their side of screen and shoot the other player. (white squares are players)
I know how to spawn one player for every started game, but I'd need to spawn 2 different prefabs, everytime when the game is started so one player can shoot to the left and the other one to the right. I also don't know how to spawn different players at different position without giving them random position. Im currently spawning one prefab two times at random position, so I'm risking that they will spawn at the same half of the screen. (there is invisible wall in the middle, so players stay at their half of the screen).
Code for spawning players
public class SpawnPlayers : MonoBehaviour {
public GameObject playerPrefab;
public float minX;
public float maxX;
public float minY;
public float maxY;
// Start is called before the first frame update
void Start() {
Vector2 randomPosition = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
PhotonNetwork.Instantiate(playerPrefab.name, randomPosition, Quaternion.identity);
}
snimek-obrazovky-2021-09-26-133347.png
(434.3 kB)
Comment