GameVsJam/3d Prototyp/Assets/Scripts/Interaction/VendingMachine.cs

47 lines
1.1 KiB
C#
Raw Normal View History

2024-04-07 14:33:44 +02:00
using System.Collections;
using System.Collections.Generic;
using Interaction;
using UnityEngine;
public class VendingMachine : MonoBehaviour
{
[SerializeField]
private PickupInteractible _pizzaPrefab;
[SerializeField]
private Transform _pizzaChute;
[SerializeField]
private float _shootForce;
2024-04-09 01:17:44 +02:00
[SerializeField]
private bool _isReady;
[SerializeField] private AudioSource _audioSource;
[SerializeField] private AudioClip _vendingMachineSound;
[SerializeField] private AudioClip _errorSound;
2024-04-07 14:33:44 +02:00
public void DropPiza()
{
2024-04-09 01:17:44 +02:00
if (_isReady)
StartCoroutine(DropPizzaRoutine());
else
_audioSource.PlayOneShot(_errorSound);
}
2024-04-07 14:33:44 +02:00
2024-04-09 01:17:44 +02:00
private IEnumerator DropPizzaRoutine()
{
_isReady = false;
_audioSource.PlayOneShot(_vendingMachineSound);
yield return new WaitForSeconds(2.7f);
PickupInteractible pizza = Instantiate(_pizzaPrefab, _pizzaChute.position, _pizzaChute.rotation);
2024-04-07 14:33:44 +02:00
pizza.GetComponent<Rigidbody>().AddForce(new Vector3(0, 0, _shootForce), ForceMode.Impulse);
2024-04-09 01:17:44 +02:00
_isReady = true;
2024-04-07 14:33:44 +02:00
}
}