Projet-IA-Madelaine/Scripts/PlayerBehaviourScripts/PlayerBehaviour.cs
2024-06-12 21:03:42 +02:00

48 lines
1.3 KiB
C#

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<PlayerScript>();
SetPlayerName(playerName);
SetPlayerColor(playerColor);
_playerRef.IsHuman = ChooseIfPlayerIsHuman();
}
protected virtual void FixedUpdate()
{
sbyte direction = ChooseDirection();
_playerRef.MoveVertically(direction,Time.deltaTime);
}
/// <summary>
/// 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.
/// </summary>
/// <returns>Returns only +1 or -1</returns>
/// <remarks>This methof is called every frames</remarks>
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);
}
}