void shoot() { flyArrow.SetActive(true); TweenPosition tp = flyArrow.GetComponent <TweenPosition>(); tp.from = new Vector3(0, -243, 0); tp.to = new Vector3(0, 257, 0); Vector3 from = tp.from; Vector3 to = tp.to; HitTimeRange hitTimeRange = getCurHitTimeRange(); //set speed //Debug.Log(slider.value); float duration = 2.0f - (2.0f - 0.5f) * slider.value; if (!isAllowHit) { if (diamond.transform.localPosition.x < 0) { hitTimeRange = getCurHitTimeRange(); if (duration >= hitTimeRange.min && duration <= hitTimeRange.max) { duration = hitTimeRange.min - 0.1f; Debug.Log("duration : " + duration); } } } tp.duration = duration; //StartCoroutine(executeAfterSecs(duration, ()=> { // tp.from = to; // tp.to = to + (to - from); // tp.ResetToBeginning(); // tp.PlayForward(); //})); EventDelegate.Add(tp.onFinished, () => { flyArrow.SetActive(false); }); tp.ResetToBeginning(); tp.PlayForward(); }
HitTimeRange getCurHitTimeRange() { float awardCurX = Mathf.Abs(diamond.transform.localPosition.x); float awardCurSpeed = 438f / diamond.GetComponent <TweenPosition>().duration / 2; Debug.Log("awardCurX : " + awardCurX); Debug.Log("awardCurSpeed : " + awardCurSpeed); HitTimeRange hitTimeRange = new HitTimeRange(); hitTimeRange.min = (awardCurX - 50) / awardCurSpeed; hitTimeRange.max = (awardCurX + 50) / awardCurSpeed; //float hitTimeMin = (awardCurX - 50) / awardCurSpeed; //float hitTimeMax = (awardCurX + 50) / awardCurSpeed; Debug.Log("min : " + hitTimeRange.min + " max : " + hitTimeRange.max); return(hitTimeRange); }