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,17 +10,30 @@ public class ResourceMaker : MonoBehaviour
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Enum.ResourceChoice _resourceChoice;
|
private Enum.ResourceChoice _resourceChoice;
|
||||||
private ResourceManager _resourceManagerInstance;
|
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()
|
private void Start()
|
||||||
{
|
{
|
||||||
_resourceManagerInstance = ResourceManager.Instance;
|
_resourceManagerInstance = ResourceManager.Instance;
|
||||||
|
_startPosition = transform.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private void Update()
|
||||||
/// D'après le choix de resource à générer, choisi le prefab à instancier
|
|
||||||
/// </summary>
|
|
||||||
public void GenerateResource()
|
|
||||||
{
|
{
|
||||||
|
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)
|
switch (_resourceChoice)
|
||||||
{
|
{
|
||||||
case Enum.ResourceChoice.Rock:
|
case Enum.ResourceChoice.Rock:
|
||||||
@ -36,3 +49,10 @@ public class ResourceMaker : MonoBehaviour
|
|||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// D'après le choix de resource à générer, choisi le prefab à instancier
|
||||||
|
/// </summary>
|
||||||
|
public void GenerateResource(){_isPlaying = true;}
|
||||||
|
}
|
||||||
|
|||||||
@ -23,13 +23,15 @@ public class ResourceTile : LevelTile
|
|||||||
{
|
{
|
||||||
_yieldCounter += Time.deltaTime * _yieldSpeed;
|
_yieldCounter += Time.deltaTime * _yieldSpeed;
|
||||||
if (_yieldCounter < 1) return;
|
if (_yieldCounter < 1) return;
|
||||||
|
if(_yieldPrefab != null)
|
||||||
|
{
|
||||||
_yieldCounter = 0;
|
_yieldCounter = 0;
|
||||||
float rangeConfig = 0.5f + _randomPositionConfig;
|
float rangeConfig = 0.5f + _randomPositionConfig;
|
||||||
Vector3 yieldPosition = new Vector3(Position.x + Random.Range(-rangeConfig, rangeConfig), Position.y, Position.z);
|
Vector3 yieldPosition = new Vector3(Position.x + Random.Range(-rangeConfig, rangeConfig), Position.y, Position.z);
|
||||||
var yielded = Instantiate(_yieldPrefab, yieldPosition, Quaternion.identity);
|
var yielded = Instantiate(_yieldPrefab, yieldPosition, Quaternion.identity);
|
||||||
yielded.transform.SetParent(LevelManager.Instance.LevelTransform);
|
yielded.transform.SetParent(LevelManager.Instance.LevelTransform);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public override bool Equals(ILevelObject other)
|
public override bool Equals(ILevelObject other)
|
||||||
{
|
{
|
||||||
return other is ResourceTile otherRes
|
return other is ResourceTile otherRes
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user