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

47 lines
1.1 KiB
C#

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;
[SerializeField]
private bool _isReady;
[SerializeField] private AudioSource _audioSource;
[SerializeField] private AudioClip _vendingMachineSound;
[SerializeField] private AudioClip _errorSound;
public void DropPiza()
{
if (_isReady)
StartCoroutine(DropPizzaRoutine());
else
_audioSource.PlayOneShot(_errorSound);
}
private IEnumerator DropPizzaRoutine()
{
_isReady = false;
_audioSource.PlayOneShot(_vendingMachineSound);
yield return new WaitForSeconds(2.7f);
PickupInteractible pizza = Instantiate(_pizzaPrefab, _pizzaChute.position, _pizzaChute.rotation);
pizza.GetComponent<Rigidbody>().AddForce(new Vector3(0, 0, _shootForce), ForceMode.Impulse);
_isReady = true;
}
}