using System; using Photon.Pun; using UnityEngine; public class SpawnObjects : MonoBehaviour { public enum SpawnRot { Identity, TransformRotation } public GameObject[] objectToSpawn; public SpawnRot spawnRot; public bool inheritScale; public bool destroyObject; public bool destroyRoot; private PhotonView view; public Action SpawnedAction; [HideInInspector] public GameObject mostRecentlySpawnedObject; private void ConfigureObject(GameObject go) { SpawnedAttack spawnedAttack = go.GetComponent(); if (!spawnedAttack) { spawnedAttack = go.AddComponent(); } spawnedAttack.spawner = base.transform.root.GetComponent(); if (!spawnedAttack.spawner) { SpawnedAttack componentInParent = base.transform.GetComponentInParent(); if ((bool)componentInParent) { componentInParent.CopySpawnedAttackTo(go); } } AttackLevel componentInParent2 = GetComponentInParent(); if ((bool)componentInParent2) { spawnedAttack.attackLevel = componentInParent2.attackLevel; } if (inheritScale) { go.transform.localScale *= base.transform.localScale.x; } if (SpawnedAction != null) { SpawnedAction(go); } } public void Spawn() { for (int i = 0; i < objectToSpawn.Length; i++) { Quaternion rotation = Quaternion.identity; if (spawnRot == SpawnRot.TransformRotation) { rotation = base.transform.rotation; } GameObject go = UnityEngine.Object.Instantiate(objectToSpawn[i], base.transform.position, rotation); ConfigureObject(go); mostRecentlySpawnedObject = go; } if (destroyObject) { UnityEngine.Object.Destroy(base.gameObject); } if (destroyRoot) { UnityEngine.Object.Destroy(base.transform.root.gameObject); } } }