Schmup-JIN/Assets/Scripts/Mover.cs

33 lines
818 B
C#
Raw Normal View History

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