Unity
- 1 ответ
- 0 вопросов
1
Вклад в тег
public abstract class Ability : ScriptableObject
{
public abstract void Activate(PlayerController playerController);
public abstract void Deactivate(PlayerController playerController);
}
[CreateAssetMenu(fileName = "Double Jump", menuName = "Abilities/Double Jump")]
public class DoubleJump : Ability
{
public override void Activate(PlayerController playerController)
{
playerController.MaxJumpCount = 2;
}
public override void Deactivate(PlayerController playerController)
{
playerController.MaxJumpCount = 1;
}
}
[RequireComponent(typeof(PlayerController))]
public class AbilityPickup : MonoBehaviour
{
private PlayerController playerController;
private List<Ability> activeAbilities = new List<Ability>();
private void Awake()
{
playerController = GetComponent<PlayerController>();
}
private void OnTriggerEnter(Collider collider)
{
if (collider.TryGetComponent(out AbilityContainer abilityContainer))
AddAbility(abilityContainer.Ability);
}
public void AddAbility(Ability ability)
{
ability.Activate(playerController);
activeAbilities.Add(ability);
}
}
public class AbilityContainer : MonoBehaviour
{
[SerializeField] private Ability ability;
public Ability Ability => ability;
}