Files
blackhole-escape/Assets/Scripts/Debugging/DebugSpawning.cs
iDunnoDev 0360907df1 Added Main menu Changes to UI
Added Rules Menu Changes to UI
Added Cutscenes to the rules scene
Reorganised Files
2022-06-22 13:30:58 +01:00

74 lines
2.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DebugSpawning : ObjectSpawning
{
public GameObject[] debugPrefabs;
private void Awake()
{
_spawnedObject = null;
_numberToSpawn = 0;
}
/// <summary>
/// Reduce the spawned counter for this spawner
/// </summary>
public override void ReduceSpawnedCount()
{
objectCount = Mathf.Clamp(objectCount - 1, 0, _numberToSpawn);
base.ReduceSpawnedCount();
}
public void DoADebugSpawn(int prefabIndex, bool randomSpawnLoc)
{
float xPos = Random.Range(-xSpawnRange, xSpawnRange);
float yPos = Random.Range(-ySpawnRange, ySpawnRange);
float zPos = Random.Range(-zSpawnRange, zSpawnRange);
Vector3 spawnLoc = Vector3.zero;
float spawnHeight = 0.0f;
// If debug is checked then try to spawn the object above the player, this is to test collisions
if (!randomSpawnLoc)
{
GameObject currentPlayer = GameObject.Find("Player");
if (currentPlayer != null)
{
PlayerHoverMovement playerHover = currentPlayer.GetComponent<PlayerHoverMovement>();
if (playerHover != null)
{
spawnLoc = currentPlayer.transform.position + (currentPlayer.transform.forward * 10.0f);
spawnHeight = playerHover.GetCurrentHeight() + 2.0f;
}
}
}
else
{
spawnLoc = new Vector3(xPos, yPos, zPos);
spawnHeight = Random.Range(minSpawnHeight, maxSpawnHeight);
}
GameObject newSpawn = Instantiate(debugPrefabs[prefabIndex]);
// Set the start height of the gameObject from the blackhole
HoverMovement newSpawnMovement = newSpawn.GetComponent<HoverMovement>();
if (newSpawnMovement)
{
newSpawnMovement.startPositionVector = spawnLoc;
newSpawnMovement.ForceHeightAdjust(spawnHeight);
}
newSpawn.SetActive(true);
objectCount++;
}
/// <summary>
/// Spawn the gameObject assigned to this spawner
/// </summary>
protected override void DoASpawn()
{
base.DoASpawn();
}
}