using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; // Auto-installs the shooting prototype (targets + HitscanShooter) whenever the // PortalTestDestination scene loads, so no scene/prefab edits are needed. If a // ShootingRange is already placed in the scene by hand, the bootstrap does nothing. public class ShootingRange : MonoBehaviour { const string SceneName = "PortalTestDestination"; [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] static void RegisterBootstrap() { SceneManager.sceneLoaded -= OnSceneLoaded; SceneManager.sceneLoaded += OnSceneLoaded; } static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (scene.name != SceneName) return; if (FindAnyObjectByType() != null) return; var go = new GameObject("ShootingRange"); SceneManager.MoveGameObjectToScene(go, scene); go.AddComponent(); } void Awake() { if (GetComponent() == null) gameObject.AddComponent(); var targets = SpawnTargets(); gameObject.AddComponent().Begin(targets); } // Positions match the greybox map from SetupPortalTestDestinationScene: central street // along Z (spawns at z = ±14), buildings at x = ±13, crates at (-2,-4) and (2,4). List SpawnTargets() { var root = new GameObject("Targets").transform; root.SetParent(transform, false); var list = new List(); // Static bots along the street, visible from either spawn. list.Add(ShootingTarget.Create(root, "Target_Street_1", new Vector3(0f, 0f, 1.5f))); list.Add(ShootingTarget.Create(root, "Target_Street_2", new Vector3(0f, 0f, -1.5f))); list.Add(ShootingTarget.Create(root, "Target_Alley_L1", new Vector3(-6f, 0f, 8f))); list.Add(ShootingTarget.Create(root, "Target_Alley_R1", new Vector3(6f, 0f, 8f))); list.Add(ShootingTarget.Create(root, "Target_Alley_L2", new Vector3(-6f, 0f, -8f))); list.Add(ShootingTarget.Create(root, "Target_Alley_R2", new Vector3(6f, 0f, -8f))); // Inside the middle buildings (visible through the street-facing doors). list.Add(ShootingTarget.Create(root, "Target_Building_L", new Vector3(-13f, 0f, 0f))); list.Add(ShootingTarget.Create(root, "Target_Building_R", new Vector3(13f, 0f, 0f))); // Strafing bots for tracking practice. list.Add(ShootingTarget.Create(root, "Target_Strafe_N", new Vector3(0f, 0f, 7f), strafeDistance: 3f)); list.Add(ShootingTarget.Create(root, "Target_Strafe_S", new Vector3(0f, 0f, -7f), strafeDistance: 3f)); return list; } }