123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using UnityEngine;
- using System.Collections;
- public class CraftBuff : MonoBehaviour
- {
- public GameObject graphic;
- public float duration;
- public float startTime;
- public virtual void init(GameObject graphicSource)
- {
- startTime = GameTime.time;
- if(graphicSource != null)
- {
- graphic = Instantiate (graphicSource) as GameObject;
- Vector3 localPosition = graphic.transform.localPosition;
- Quaternion localRotation = graphic.transform.localRotation;
- graphic.transform.parent = this.gameObject.transform;
- graphic.transform.localPosition = localPosition;
- graphic.transform.localRotation = localRotation;
- }
- }
- // Update is called once per frame
- public virtual void Update ()
- {
- if(GameTime.time - startTime >= duration)
- {
- end ();
- }
- }
- public virtual void end ()
- {
- if(graphic != null)
- {
- CraftBuffGraphics cbg = graphic.GetComponent<CraftBuffGraphics>();
- if(cbg != null)
- {
- cbg.remove();
- }
- else
- {
- Destroy(graphic);
- }
- }
- Destroy (this);
- }
- }
|