2019-09-17 15:43:40 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2019-09-17 18:52:55 +02:00
|
|
|
|
public class Mover : MonoBehaviour
|
2019-09-17 15:43:40 +02:00
|
|
|
|
{
|
2019-09-17 18:52:55 +02:00
|
|
|
|
private AbstractCharacter _character;
|
|
|
|
|
private Transform _transform;
|
|
|
|
|
private Vector2 _direction;
|
|
|
|
|
private float _maxSpeed;
|
2019-09-17 20:30:20 +02:00
|
|
|
|
public float MaxSpeed
|
|
|
|
|
{
|
|
|
|
|
get { return _maxSpeed; }
|
|
|
|
|
set { _maxSpeed = value; }
|
|
|
|
|
}
|
2019-09-17 18:52:55 +02:00
|
|
|
|
|
|
|
|
|
public Vector2 Direction
|
2019-09-17 15:43:40 +02:00
|
|
|
|
{
|
2019-09-17 18:52:55 +02:00
|
|
|
|
get { return _direction; }
|
|
|
|
|
set { _direction = value; }
|
2019-09-17 15:43:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 20:30:20 +02:00
|
|
|
|
void Awake()
|
2019-09-17 18:52:55 +02:00
|
|
|
|
{
|
|
|
|
|
_transform = GetComponentInParent<Transform>();
|
|
|
|
|
_character = GetComponentInParent<AbstractCharacter>();
|
2019-09-17 20:30:20 +02:00
|
|
|
|
_maxSpeed = _character != null ? _character.MaxSpeed : 1;
|
2019-09-17 18:52:55 +02:00
|
|
|
|
_direction = Vector2.zero;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 15:43:40 +02:00
|
|
|
|
void Update()
|
|
|
|
|
{
|
2019-09-17 18:52:55 +02:00
|
|
|
|
_maxSpeed = _character.MaxSpeed;
|
|
|
|
|
Vector2 currentPosition = _transform.position;
|
|
|
|
|
_transform.position = currentPosition + _maxSpeed * Time.deltaTime * _direction;
|
2019-09-17 15:43:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|