Added Car Alarm Super Surprise
This commit is contained in:
parent
4a43478f60
commit
2a17422db5
3 changed files with 52 additions and 1 deletions
28
Assets/Scripts/CarAlarm.cs
Normal file
28
Assets/Scripts/CarAlarm.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using UnityEngine;
|
||||
using System.Collections; // Needed for IEnumerator
|
||||
|
||||
public class CarAlarm : MonoBehaviour
|
||||
{
|
||||
public AudioSource alarmSound; // Car alarm sound
|
||||
public Light alarmLight; // Car alarm light (flashing)
|
||||
private bool alarmTriggered = false;
|
||||
|
||||
public void TriggerAlarm()
|
||||
{
|
||||
if (!alarmTriggered)
|
||||
{
|
||||
alarmTriggered = true;
|
||||
alarmSound.Play(); // Play the alarm sound
|
||||
StartCoroutine(FlashLight()); // Start flashing light
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FlashLight()
|
||||
{
|
||||
while (alarmTriggered)
|
||||
{
|
||||
alarmLight.enabled = !alarmLight.enabled;
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CarAlarm.cs.meta
Normal file
11
Assets/Scripts/CarAlarm.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4e3048465712b354b8d001512a3ec017
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -5,7 +5,10 @@ public class CartReturnZone : MonoBehaviour
|
|||
{
|
||||
public TMP_Text scoreText; // Reference to the TMP text
|
||||
public AudioSource returnSound; // Sound to play when cart is returned
|
||||
public CarAlarm carAlarm; // Reference to the CarAlarm script
|
||||
private int score = 0;
|
||||
public int cartsNeeded = 2; // Number of carts required to trigger alarm
|
||||
private int cartsReturned = 0; // Counter for returned carts
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
|
|
@ -16,7 +19,16 @@ public class CartReturnZone : MonoBehaviour
|
|||
|
||||
returnSound.Play(); // Play sound when cart is returned
|
||||
|
||||
// Optional: Destroy the cart or move it away
|
||||
// Increase the cart return counter
|
||||
cartsReturned++;
|
||||
|
||||
// Check if enough carts have been returned
|
||||
if (cartsReturned >= cartsNeeded)
|
||||
{
|
||||
carAlarm?.TriggerAlarm(); // Trigger the alarm
|
||||
}
|
||||
|
||||
// Optionally: Destroy or deactivate the cart when it's returned
|
||||
Destroy(other.gameObject);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue