using UnityEngine; public abstract class PlayerBehaviour : MonoBehaviour { protected PlayerScript _playerRef; protected string playerName; protected Color playerColor; protected virtual void Awake() { playerName = ChoosePlayerName(); playerColor = ChoosePlayerColor(); _playerRef = gameObject.GetComponent(); SetPlayerName(playerName); SetPlayerColor(playerColor); _playerRef.IsHuman = ChooseIfPlayerIsHuman(); } protected virtual void FixedUpdate() { sbyte direction = ChooseDirection(); _playerRef.MoveVertically(direction,Time.deltaTime); } /// /// This method choose if the player goes up (+1) or down (-1). /// The way the decision is made is up to you. /// This method must return either +1 or -1 ONLY. /// /// Returns only +1 or -1 /// This methof is called every frames protected abstract sbyte ChooseDirection(); protected abstract string ChoosePlayerName(); protected abstract Color ChoosePlayerColor(); protected abstract bool ChooseIfPlayerIsHuman(); private void SetPlayerName(string name) { _playerRef.SetName(name); } private void SetPlayerColor(Color color) { _playerRef.SetColor(color); } }