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(); if(cbg != null) { cbg.remove(); } else { Destroy(graphic); } } Destroy (this); } }