Advertisement
Powerhoof

SpriteAnim Effect Example

Oct 12th, 2016
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using PowerTools;
  4.  
  5. /// Plays an animation and then destroys itself
  6. [RequireComponent(typeof(SpriteAnim))]
  7. public class Effect : MonoBehaviour
  8. {  
  9.     [SerializeField, Tooltip("The animation to play!")]
  10.     AnimationClip m_animation = null;
  11.  
  12.     SpriteAnim m_spriteAnim = null;
  13.  
  14.     // Use this for initialization
  15.     void Start ()
  16.     {
  17.         // Store the sprite animation component so we don't have to get it again every frame
  18.         m_spriteAnim = GetComponent<SpriteAnim>();
  19.  
  20.         // Play the animation
  21.         m_spriteAnim.Play(m_animation);
  22.     }
  23.    
  24.     // Update is called once per frame
  25.     void Update ()
  26.     {
  27.         // If the animation has finished playing, destroy the object
  28.         if ( m_spriteAnim.IsPlaying() == false )
  29.             Destroy(gameObject);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement