Added Car Alarm Super Surprise
This commit is contained in:
parent
8dfbd22a9e
commit
f737955a88
10 changed files with 1240 additions and 304 deletions
50
Assets/Scripts/CartSpawner.cs
Normal file
50
Assets/Scripts/CartSpawner.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class CartSpawner : MonoBehaviour
|
||||
{
|
||||
public GameObject cartPrefab;
|
||||
public Vector3 spawnAreaCenter;
|
||||
public Vector3 spawnAreaSize;
|
||||
public float spawnInterval = 10f; // Time (seconds) between spawns
|
||||
public int maxCartsInScene = 5; // Prevent too many carts
|
||||
|
||||
private int currentCarts = 0;
|
||||
|
||||
void Start()
|
||||
{
|
||||
StartCoroutine(SpawnCartsOverTime());
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator SpawnCartsOverTime()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (currentCarts < maxCartsInScene)
|
||||
{
|
||||
Vector3 spawnPosition = GetRandomPositionInArea();
|
||||
GameObject newCart = Instantiate(cartPrefab, spawnPosition, Quaternion.identity);
|
||||
currentCarts++;
|
||||
|
||||
// When cart is returned/destroyed, decrement the counter
|
||||
CartTracker tracker = newCart.AddComponent<CartTracker>();
|
||||
tracker.spawner = this;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(spawnInterval);
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 GetRandomPositionInArea()
|
||||
{
|
||||
float x = Random.Range(-spawnAreaSize.x / 2, spawnAreaSize.x / 2);
|
||||
float z = Random.Range(-spawnAreaSize.z / 2, spawnAreaSize.z / 2);
|
||||
float y = spawnAreaCenter.y;
|
||||
|
||||
return spawnAreaCenter + new Vector3(x, 0f, z);
|
||||
}
|
||||
|
||||
public void CartRemoved()
|
||||
{
|
||||
currentCarts--;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CartSpawner.cs.meta
Normal file
11
Assets/Scripts/CartSpawner.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 40621e6d3a4e6ed429913f31cb7221a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/CartTracker.cs
Normal file
14
Assets/Scripts/CartTracker.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class CartTracker : MonoBehaviour
|
||||
{
|
||||
public CartSpawner spawner;
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (spawner != null)
|
||||
{
|
||||
spawner.CartRemoved();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CartTracker.cs.meta
Normal file
11
Assets/Scripts/CartTracker.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d11eb3a23e430834b99cc3ad0b769300
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/MainMenuController.cs
Normal file
35
Assets/Scripts/MainMenuController.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class MainMenuController : MonoBehaviour
|
||||
{
|
||||
public GameObject startMenuUI;
|
||||
public GameObject gameUI;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Time.timeScale = 0f;
|
||||
startMenuUI.SetActive(true);
|
||||
if (gameUI != null)
|
||||
gameUI.SetActive(false);
|
||||
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
startMenuUI.SetActive(false);
|
||||
if (gameUI != null)
|
||||
gameUI.SetActive(true);
|
||||
Time.timeScale = 1f;
|
||||
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
public void QuitGame()
|
||||
{
|
||||
Debug.Log("Quitting game...");
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MainMenuController.cs.meta
Normal file
11
Assets/Scripts/MainMenuController.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8fd46f649f628e04ba6adc84b937ba97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -22,7 +22,7 @@ public class PlayerGrabber : MonoBehaviour
|
|||
|
||||
if (heldCart != null)
|
||||
{
|
||||
heldCart.HoldCart(); // Let it keep following while held
|
||||
heldCart.HoldCart();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue