trotFunky
98402a90f7
Made Speed a property to allow other Objects that are not Characters to use the Mover Init in Awake() to allow other objects to modify its properties during their Start()
37 lines
950 B
C#
37 lines
950 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Mover : MonoBehaviour
|
|
{
|
|
private AbstractCharacter _character;
|
|
private Transform _transform;
|
|
private Vector2 _direction;
|
|
private float _maxSpeed;
|
|
public float MaxSpeed
|
|
{
|
|
get { return _maxSpeed; }
|
|
set { _maxSpeed = value; }
|
|
}
|
|
|
|
public Vector2 Direction
|
|
{
|
|
get { return _direction; }
|
|
set { _direction = value; }
|
|
}
|
|
|
|
void Awake()
|
|
{
|
|
_transform = GetComponentInParent<Transform>();
|
|
_character = GetComponentInParent<AbstractCharacter>();
|
|
_maxSpeed = _character != null ? _character.MaxSpeed : 1;
|
|
_direction = Vector2.zero;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
_maxSpeed = _character.MaxSpeed;
|
|
Vector2 currentPosition = _transform.position;
|
|
_transform.position = currentPosition + _maxSpeed * Time.deltaTime * _direction;
|
|
}
|
|
}
|