ResourceTile produit des yields que lorsqu'une yield prefab a été déterminé
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
/// <summary>
|
|
/// Gère la production de ressource et sert de minuteur pour laisser la ressource sur le sol.
|
|
/// </summary>
|
|
public class ResourceMaker : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private int _resourceMakingAmount;
|
|
[SerializeField]
|
|
private Enum.ResourceChoice _resourceChoice;
|
|
private ResourceManager _resourceManagerInstance;
|
|
[SerializeField]
|
|
private Vector2 _endPosition;
|
|
private Vector2 _startPosition;
|
|
private float _desiredTime = 1.5f;
|
|
private float _timePassed = 0f;
|
|
private bool _isPlaying = false;
|
|
|
|
private void Start()
|
|
{
|
|
_resourceManagerInstance = ResourceManager.Instance;
|
|
_startPosition = transform.position;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_isPlaying)
|
|
{
|
|
_timePassed += Time.deltaTime;
|
|
float duration = _timePassed / _desiredTime;
|
|
duration = duration * duration * (3.0f - 2.0f * duration);
|
|
transform.position = Vector2.Lerp(_startPosition, _endPosition, duration);
|
|
if(Vector2.Distance(transform.position,_endPosition) < 0.01f)
|
|
{
|
|
_isPlaying = false;
|
|
switch (_resourceChoice)
|
|
{
|
|
case Enum.ResourceChoice.Rock:
|
|
_resourceManagerInstance.RockAmount = _resourceMakingAmount;
|
|
break;
|
|
case Enum.ResourceChoice.Wood:
|
|
_resourceManagerInstance.WoodAmount = _resourceMakingAmount;
|
|
break;
|
|
case Enum.ResourceChoice.Food:
|
|
_resourceManagerInstance.FoodAmount = _resourceMakingAmount;
|
|
break;
|
|
}
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// D'après le choix de resource à générer, choisi le prefab à instancier
|
|
/// </summary>
|
|
public void GenerateResource(){_isPlaying = true;}
|
|
}
|