Мой вопрос: почему это происходит? и почему он не сломался раньше? есть ли способ решить эту проблему и вызвать все функции?
Вот код Sacrificeable:
Код: Выделить всё
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(DetectClicks))]
public class Sacrificeable : MonoBehaviour
{
public CardPlay reference;
[SerializeField] bool sacrifice;
private bool _sacrifice;
public bool Sacrifice
{
get => _sacrifice;
set
{
sacrifice = _sacrifice;
if (value == _sacrifice)
return;
sacrifice = _sacrifice = value;
alternator?.Invoke();
}
}
private DetectClicks detector;
private void Start()
{
TryGetComponent(out CardPlay card);
reference = reference ? reference : card;
alternator = Selected_;
detector = GetComponent();
reference.OnPlay += Enable;
}
private Action alternator;
private void Selected_()
{
Selected?.Invoke();
alternator = Unselected_;
}
private void Unselected_()
{
Unselected?.Invoke();
alternator = Selected_;
}
public event Action Selected;
public event Action Unselected;
public void Enable()
{
print("Enabled");
detector.Click -= Opposer;
detector.Click += Opposer;
}
private void Opposer()
{
Sacrifice = !Sacrifice;
}
private void OnValidate()
{
Sacrifice = sacrifice;
}
}
Код: Выделить всё
using System;
using UnityEngine;
[RequireComponent(typeof(Collider2D))]
public class DetectClicks : MonoBehaviour
{
public event Action Click;
public event Action Release;
public event Action Enter;
public event Action Exit;
public Collider[] Colliders => gameObject.GetComponents();
private void Awake()
{
Click += () => print("Truly invoked");
}
public void OnMouseDown()
{
Click();
Debug.Log("Detected");
}
public void OnMouseUp() => Release?.Invoke();
public void OnMouseEnter() => Enter?.Invoke();
public void OnMouseExit() => Exit?.Invoke();
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... ring-event