Advertisement
Guest User

ScoreAnimation

a guest
Dec 10th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using JetBrains.Annotations;
  2. using UnityEngine;
  3.  
  4. namespace Scripts.MonoBehaviours
  5. {
  6.     public class ScoreAnimation : MonoBehaviour
  7.     {
  8.         private const string CorrectAnimName = "ScoreCorrectly";
  9.         private const string IncorrectAnimName = "ScoreIncorrectly";
  10.  
  11.         [SerializeField]
  12.         private bool isOpponent;
  13.  
  14.         [UsedImplicitly]
  15.         private void Start()
  16.         {
  17.             if (isOpponent)
  18.             {
  19.                 FindObjectOfType<OpponentMotionReceiver>().Released += MotionHandler;
  20.             }
  21.             else
  22.             {
  23.                 FindObjectOfType<BlockMotion>().Released += MotionHandler;
  24.             }
  25.         }
  26.  
  27.         [UsedImplicitly]
  28.         private void OnDestroy()
  29.         {
  30.             if (isOpponent)
  31.             {
  32.                 var motionReceiver = FindObjectOfType<OpponentMotionReceiver>();
  33.  
  34.                 if (motionReceiver != null)
  35.                 {
  36.                     FindObjectOfType<OpponentMotionReceiver>().Released -= MotionHandler;
  37.                 }
  38.                 else
  39.                 {
  40.                     Debug.Log("motion receiver not found");
  41.                 }
  42.             }
  43.         }
  44.  
  45.         private void MotionHandler(object sender, BlockReleasedEventArgs args)
  46.         {
  47.             GetComponent<Animation>().Play(args.Correct ? CorrectAnimName : IncorrectAnimName);
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement