riversong code showcase
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
public class WindmillProducerAnimation : ProducerAnimation
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform _rotationTarget;
|
||||
|
||||
[SerializeField]
|
||||
private float _rotationSpeed = 180;
|
||||
|
||||
[SerializeField]
|
||||
private float _rampUpTime = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
private float _slowDownTime = 0.5f;
|
||||
|
||||
private float _currentRotationSpeed;
|
||||
|
||||
public override void UpdateAnimation(in BuildingProductionState productionState)
|
||||
{
|
||||
if (!_rotationTarget) return;
|
||||
|
||||
var isWorking = productionState.State == ProducerState.Working;
|
||||
var targetRotationSpeed = isWorking ? _rotationSpeed : 0;
|
||||
var rampTime = isWorking ? _rampUpTime : _slowDownTime;
|
||||
var maxDelta = rampTime > 0 ? _rotationSpeed / rampTime * Time.deltaTime : _rotationSpeed;
|
||||
_currentRotationSpeed = Mathf.MoveTowards(_currentRotationSpeed, targetRotationSpeed, maxDelta);
|
||||
|
||||
var rotationDelta = _currentRotationSpeed * Time.deltaTime;
|
||||
_rotationTarget.localRotation *= Quaternion.Euler(0, 0, rotationDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user