ResourceMaker déplace la ressource à ramasser vers un point fixe avant d'augmenter la quantité de ressources du joueur
ResourceTile produit des yields que lorsqu'une yield prefab a été déterminé
This commit is contained in:
parent
ede4cbdf5c
commit
482fc2c178
@ -10,29 +10,49 @@ public class ResourceMaker : MonoBehaviour
|
||||
[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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
public void GenerateResource(){_isPlaying = true;}
|
||||
}
|
||||
|
||||
@ -23,12 +23,14 @@ public class ResourceTile : LevelTile
|
||||
{
|
||||
_yieldCounter += Time.deltaTime * _yieldSpeed;
|
||||
if (_yieldCounter < 1) return;
|
||||
|
||||
_yieldCounter = 0;
|
||||
float rangeConfig = 0.5f + _randomPositionConfig;
|
||||
Vector3 yieldPosition = new Vector3(Position.x + Random.Range(-rangeConfig, rangeConfig), Position.y, Position.z);
|
||||
var yielded = Instantiate(_yieldPrefab, yieldPosition, Quaternion.identity);
|
||||
yielded.transform.SetParent(LevelManager.Instance.LevelTransform);
|
||||
if(_yieldPrefab != null)
|
||||
{
|
||||
_yieldCounter = 0;
|
||||
float rangeConfig = 0.5f + _randomPositionConfig;
|
||||
Vector3 yieldPosition = new Vector3(Position.x + Random.Range(-rangeConfig, rangeConfig), Position.y, Position.z);
|
||||
var yielded = Instantiate(_yieldPrefab, yieldPosition, Quaternion.identity);
|
||||
yielded.transform.SetParent(LevelManager.Instance.LevelTransform);
|
||||
}
|
||||
}
|
||||
public override bool Equals(ILevelObject other)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user