Updated moving platform script
This commit is contained in:
@@ -5,25 +5,49 @@ namespace Platforms
|
||||
{
|
||||
public class MovingPlatform : MonoBehaviour, IMovement
|
||||
{
|
||||
public float xOffeset;
|
||||
public float yOffset;
|
||||
|
||||
private Rigidbody2D _platformRigidbody;
|
||||
|
||||
private Vector3 _velocity = Vector3.zero;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_platformRigidbody = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!IsPaused)
|
||||
Move(BaseSpeed);
|
||||
}
|
||||
|
||||
// PAUSING METHODS
|
||||
|
||||
public bool IsPaused { get; }
|
||||
public bool IsPaused { get; private set; }
|
||||
public void Pause()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
IsPaused = true;
|
||||
_platformRigidbody.simulated = !IsPaused;
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
IsPaused = false;
|
||||
_platformRigidbody.simulated = !IsPaused;
|
||||
}
|
||||
|
||||
// MOVEMENT METHODS
|
||||
|
||||
public float BaseSpeed { get; set; }
|
||||
|
||||
public void Move(float value)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
var position = transform.position;
|
||||
var targetPosition = new Vector3(position.x + xOffeset, position.y + yOffset, 0.0f);
|
||||
position = Vector3.SmoothDamp(position, targetPosition, ref _velocity, 1.0f);
|
||||
transform.position = position;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user