CraftBuff.cs 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using System.Collections;
  3. public class CraftBuff : MonoBehaviour
  4. {
  5. public GameObject graphic;
  6. public float duration;
  7. public float startTime;
  8. public virtual void init(GameObject graphicSource)
  9. {
  10. startTime = GameTime.time;
  11. if(graphicSource != null)
  12. {
  13. graphic = Instantiate (graphicSource) as GameObject;
  14. Vector3 localPosition = graphic.transform.localPosition;
  15. Quaternion localRotation = graphic.transform.localRotation;
  16. graphic.transform.parent = this.gameObject.transform;
  17. graphic.transform.localPosition = localPosition;
  18. graphic.transform.localRotation = localRotation;
  19. }
  20. }
  21. // Update is called once per frame
  22. public virtual void Update ()
  23. {
  24. if(GameTime.time - startTime >= duration)
  25. {
  26. end ();
  27. }
  28. }
  29. public virtual void end ()
  30. {
  31. if(graphic != null)
  32. {
  33. CraftBuffGraphics cbg = graphic.GetComponent<CraftBuffGraphics>();
  34. if(cbg != null)
  35. {
  36. cbg.remove();
  37. }
  38. else
  39. {
  40. Destroy(graphic);
  41. }
  42. }
  43. Destroy (this);
  44. }
  45. }