FiE-Game/Assets/Photon Unity Networking/UtilityScripts/OnJoinedInstantiate.cs
2023-07-19 18:11:02 +01:00

33 lines
986 B
C#

using UnityEngine;
using System.Collections;
public class OnJoinedInstantiate : MonoBehaviour
{
public Transform SpawnPosition;
public float PositionOffset = 2.0f;
public GameObject[] PrefabsToInstantiate; // set in inspector
public void OnJoinedRoom()
{
if (this.PrefabsToInstantiate != null)
{
foreach (GameObject o in this.PrefabsToInstantiate)
{
Debug.Log("Instantiating: " + o.name);
Vector3 spawnPos = Vector3.up;
if (this.SpawnPosition != null)
{
spawnPos = this.SpawnPosition.position;
}
Vector3 random = Random.insideUnitSphere;
random.y = 0;
random = random.normalized;
Vector3 itempos = spawnPos + this.PositionOffset * random;
PhotonNetwork.Instantiate(o.name, itempos, Quaternion.identity, 0);
}
}
}
}