Files

30 lines
536 B
C#
Raw Permalink Normal View History

2021-10-25 17:27:40 +02:00
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class MoveInDirection : MonoBehaviour
{
[SerializeField] private float _speed = 4.0f;
2021-12-16 12:05:35 +01:00
[SerializeField] private bool _isFixed = default;
private Rigidbody2D _rigidbody;
public Vector2 Direction { get; set; }
2021-10-25 17:27:40 +02:00
void Awake()
{
_rigidbody = GetComponent<Rigidbody2D>();
}
void Update()
2021-12-16 12:05:35 +01:00
{
if (_isFixed)
{
2021-12-18 01:52:24 +01:00
_rigidbody.velocity = (transform.right * transform.root.localScale.x) * _speed;
2021-12-16 12:05:35 +01:00
}
else
{
_rigidbody.velocity = Direction * _speed;
}
2021-10-25 17:27:40 +02:00
}
}