using UnityEngine.UI; using UnityEngine; public class DropCoinImage : MonoBehaviour { Button tmpBtn; FlyImage flyImage; /// /// Awake is called when the script instance is being loaded. /// void Awake() { tmpBtn = transform.GetComponent(); flyImage = transform.GetComponent(); tmpBtn.onClick.AddListener(OnClick); } private void OnClick() { StartFly(); } bool countdown; float timer; public void Init() { timer = 0; countdown = true; tmpBtn.interactable = true; } // Update is called once per frame void Update() { if (countdown) { timer += Time.deltaTime; if (timer >= 3) { countdown = false; StartFly(); } } } private void StartFly() { tmpBtn.interactable = false; RectTransform end = GameObject.Find("UICamera/MainUI/FlyEndPos").GetComponent(); flyImage.SetDestination(null, transform.position, end.position, true); } }