Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using JetBrains.Annotations;
- using UnityEngine;
- namespace Scripts.MonoBehaviours
- {
- public class ScoreAnimation : MonoBehaviour
- {
- private const string CorrectAnimName = "ScoreCorrectly";
- private const string IncorrectAnimName = "ScoreIncorrectly";
- [SerializeField]
- private bool isOpponent;
- [UsedImplicitly]
- private void Start()
- {
- if (isOpponent)
- {
- FindObjectOfType<OpponentMotionReceiver>().Released += MotionHandler;
- }
- else
- {
- FindObjectOfType<BlockMotion>().Released += MotionHandler;
- }
- }
- [UsedImplicitly]
- private void OnDestroy()
- {
- if (isOpponent)
- {
- var motionReceiver = FindObjectOfType<OpponentMotionReceiver>();
- if (motionReceiver != null)
- {
- FindObjectOfType<OpponentMotionReceiver>().Released -= MotionHandler;
- }
- else
- {
- Debug.Log("motion receiver not found");
- }
- }
- }
- private void MotionHandler(object sender, BlockReleasedEventArgs args)
- {
- GetComponent<Animation>().Play(args.Correct ? CorrectAnimName : IncorrectAnimName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement