using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
///
/// Auto-setup script to configure the game scene.
/// Drag this onto an empty GameObject called "GameManager" to auto-configure everything.
///
public class GameSetup : MonoBehaviour
{
[Header("Player Setup")]
[Tooltip("The T-Rex player prefab or create one")]
public GameObject trexPrefab;
[Tooltip("Auto-create a basic T-Rex")]
public bool createBasicTrex = true;
[Tooltip("Spawn position for player")]
public Vector3 playerSpawnPos = Vector3.zero;
[Header("World")]
[Tooltip("Generate terrain automatically")]
public bool generateTerrain = true;
[Tooltip("Add skybox")]
public bool addSkybox = true;
[Header("Lighting")]
[Tooltip("Add directional light")]
public bool addDirectionalLight = true;
[Header("Enemies")]
[Tooltip("Auto-create enemy dinosaurs")]
public bool createEnemies = true;
[Tooltip("Number of enemy dinosaurs")]
public int enemyCount = 5;
[Tooltip("Enemy spawn radius from player")]
public float enemySpawnRadius = 50f;
[Header("UI")]
[Tooltip("Create basic health bar UI")]
public bool createHealthBarUI = true;
void Start()
{
Debug.Log("🎮 Setting up Super Dino Smash...");
SetupLighting();
SetupWorld();
SetupPlayer();
SetupEnemies();
SetupUI();
Debug.Log("✅ Setup complete! Press Play to start the game.");
}
void SetupLighting()
{
if (addDirectionalLight)
{
// Check if directional light exists
if (FindAnyObjectByType() == null)
{
GameObject sun = new GameObject("Sun");
Light dirLight = sun.AddComponent();
dirLight.type = LightType.Directional;
dirLight.color = Color.white;
dirLight.intensity = 1f;
dirLight.transform.rotation = Quaternion.Euler(50f, 30f, 0f);
// Add shadows (Unity 6 compatible)
dirLight.shadows = LightShadows.Soft;
Debug.Log("☀️ Added directional light");
}
}
// Setup ambient light (Unity 6 compatible)
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;
RenderSettings.fog = true;
RenderSettings.fogColor = new Color(0.5f, 0.6f, 0.7f);
RenderSettings.fogMode = FogMode.Exponential;
RenderSettings.fogStartDistance = 30f;
RenderSettings.fogEndDistance = 120f;
}
void SetupWorld()
{
if (generateTerrain)
{
// Check if terrain exists
if (FindAnyObjectByType() == null)
{
GameObject terrainObj = new GameObject("Terrain");
Terrain terrain = terrainObj.AddComponent();
TerrainData terrainData = new TerrainData();
terrainData.heightmapResolution = 257;
terrainData.size = new Vector3(512, 20, 512);
terrain.terrainData = terrainData;
Debug.Log("🌍 Created basic terrain");
}
}
if (addSkybox)
{
// Use default skybox or set a color
RenderSettings.skybox = Resources.Load("Skybox");
if (RenderSettings.skybox == null)
{
// Fallback to blue sky
RenderSettings.skybox = null;
// Use default sky
}
}
// Add ground plane if no terrain
if (FindAnyObjectByType() == null)
{
GameObject ground = GameObject.CreatePrimitive(PrimitiveType.Plane);
ground.name = "Ground";
ground.transform.position = Vector3.zero;
ground.transform.localScale = new Vector3(50f, 50f, 50f);
Debug.Log("🟫 Created ground plane");
}
}
void SetupPlayer()
{
if (createBasicTrex || trexPrefab == null)
{
CreateBasicTrex();
}
else
{
Instantiate(trexPrefab, playerSpawnPos, Quaternion.identity);
}
}
void CreateBasicTrex()
{
// Create T-Rex GameObject
GameObject trex = new GameObject("T-Rex");
trex.tag = "Player";
trex.transform.position = playerSpawnPos;
// Add capsule body
GameObject body = GameObject.CreatePrimitive(PrimitiveType.Capsule);
body.name = "Body";
body.transform.SetParent(trex.transform);
body.transform.localPosition = Vector3.zero;
body.transform.localScale = new Vector3(1f, 2f, 1f);
// Green material
Material greenMat = new Material(Shader.Find("Standard"));
greenMat.color = Color.green;
body.GetComponent().material = greenMat;
// Remove collider from body (CharacterController handles this)
Destroy(body.GetComponent());
// Add components
CharacterController controller = trex.AddComponent();
controller.height = 3f;
controller.radius = 0.8f;
TrexController playerController = trex.AddComponent();
CombatSystem combat = trex.AddComponent();
combat.maxHealth = 100f;
combat.biteDamage = 25f;
// Note: Add Animator component manually in Unity with an Animator Controller
// trex.AddComponent();
Debug.Log("🦖 Created T-Rex player at " + playerSpawnPos);
}
void SetupEnemies()
{
if (!createEnemies) return;
Debug.Log($"🌋 Creating {enemyCount} enemy dinosaurs...");
// Create a spawn manager
GameObject spawner = new GameObject("DinoSpawnManager");
DinoSpawnManager spawnManager = spawner.AddComponent();
spawnManager.maxDinos = enemyCount;
spawnManager.useRandomSpawn = true;
spawnManager.spawnRadius = enemySpawnRadius;
spawnManager.spawnCenter = playerSpawnPos;
// Create enemy dino prefabs
List enemyPrefabs = new List();
// Raptor type (fast, small)
GameObject raptor = CreateBasicEnemyDino("Raptor", Color.red, 0.8f, 1.5f, 50f, 10f);
enemyPrefabs.Add(raptor);
// Stegosaurus type (medium, tanky)
GameObject stego = CreateBasicEnemyDino("Stegosaurus", Color.yellow, 1.2f, 2.5f, 100f, 15f);
enemyPrefabs.Add(stego);
// Triceratops type (large, slow)
GameObject trike = CreateBasicEnemyDino("Triceratops", Color.cyan, 1.5f, 3f, 150f, 20f);
enemyPrefabs.Add(trike);
spawnManager.dinoPrefabs = enemyPrefabs.ToArray();
// Spawn initial wave immediately
for (int i = 0; i < enemyCount; i++)
{
GameObject prefab = enemyPrefabs[i % enemyPrefabs.Count];
float angle = (i * 360f / enemyCount) * Mathf.Deg2Rad;
float radius = Random.Range(20f, enemySpawnRadius);
Vector3 spawnPos = new Vector3(
playerSpawnPos.x + Mathf.Cos(angle) * radius,
1f,
playerSpawnPos.z + Mathf.Sin(angle) * radius
);
GameObject dino = Instantiate(prefab, spawnPos, Quaternion.identity);
Debug.Log($"🦕 Spawned {dino.name} at {spawnPos:F1}");
}
Debug.Log($"✅ Created {enemyCount} enemy dinosaurs!");
}
GameObject CreateBasicEnemyDino(string name, Color color, float scale, float height, float health, float damage)
{
GameObject dino = new GameObject(name);
dino.tag = "Enemy";
dino.layer = LayerMask.NameToLayer("Default");
// Body
GameObject body = GameObject.CreatePrimitive(PrimitiveType.Capsule);
body.name = "Body";
body.transform.SetParent(dino.transform);
body.transform.localPosition = Vector3.zero;
body.transform.localScale = new Vector3(scale, height, scale);
Material mat = new Material(Shader.Find("Standard"));
mat.color = color;
body.GetComponent().material = mat;
// Remove collider (we'll add our own)
Destroy(body.GetComponent());
// Add Rigidbody for physics
Rigidbody rb = dino.AddComponent();
rb.mass = 2f * scale;
rb.useGravity = true;
rb.freezeRotation = true;
// Add capsule collider for combat detection
CapsuleCollider collider = dino.AddComponent();
collider.height = height;
collider.radius = scale * 0.5f;
collider.isTrigger = true;
// Add AI controller
AIController ai = dino.AddComponent();
ai.attackRange = 5f;
ai.walkSpeed = 4f;
ai.chaseSpeed = 7f;
// Add combat system
CombatSystem combat = dino.AddComponent();
combat.maxHealth = health;
combat.biteDamage = damage;
return dino;
}
void SetupUI()
{
if (createHealthBarUI)
{
// Create canvas
if (FindAnyObjectByType