2020-03-18 02:04:33 +01:00
|
|
|
|
using UnityEngine;
|
2020-03-05 00:48:39 +01:00
|
|
|
|
using UnityAtoms.BaseAtoms;
|
|
|
|
|
|
2020-03-18 02:04:33 +01:00
|
|
|
|
namespace UnityAtoms.Examples
|
2020-03-05 00:48:39 +01:00
|
|
|
|
{
|
2020-03-20 01:29:39 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a constant velocity on the attached Rigidbody 2D.
|
|
|
|
|
/// </summary>
|
2020-03-18 02:04:33 +01:00
|
|
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
|
|
|
public class MoveInDirection : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public float Speed { set => _speed.Value = value; }
|
2020-03-05 00:48:39 +01:00
|
|
|
|
|
2020-03-18 02:04:33 +01:00
|
|
|
|
[SerializeField]
|
|
|
|
|
private FloatReference _speed;
|
2020-03-05 00:48:39 +01:00
|
|
|
|
|
2020-03-18 02:04:33 +01:00
|
|
|
|
private Rigidbody2D rb;
|
2020-03-05 00:48:39 +01:00
|
|
|
|
|
2020-03-18 02:04:33 +01:00
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
rb = GetComponent<Rigidbody2D>();
|
|
|
|
|
rb.isKinematic = true;
|
|
|
|
|
}
|
2020-03-05 00:48:39 +01:00
|
|
|
|
|
2020-03-18 02:04:33 +01:00
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
rb.velocity = transform.right * _speed.Value;
|
|
|
|
|
}
|
2020-03-05 00:48:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|