Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private BallMovement ballMovement;
- public AnimationCurve frisbeeCurve = new AnimationCurve();
- [SerializeField] float duration;
- public Transform endPoint;
- void Start()
- {
- ballMovement = (BallMovement)Random.Range(0, 4);
- if (ballMovement == BallMovement.left)
- {
- transform.position = GameManager.instance.leftPosition.position;
- endPoint = GameManager.instance.rightPosition;
- endPoint.position = new Vector3(endPoint.position.x, Random.Range((endPoint.position.y - 300), (endPoint.position.y + 300)), endPoint.position.z);
- }
- else if (ballMovement == BallMovement.right)
- {
- return;
- }
- else if (ballMovement == BallMovement.top)
- {
- return;
- }
- else if (ballMovement == BallMovement.Down)
- {
- return;
- }
- GetComponent<RectTransform>().DOMove(endPoint.position, 4f);
- }
- private void OnTriggerEnter2D(Collider2D other)
- {
- if (ballMovement == BallMovement.left && other.gameObject.CompareTag("flip"))
- {
- DOTween.Kill(this.gameObject);
- Debug.Log("Trigger");
- StartCoroutine(FlyBack(duration));
- }
- }
- IEnumerator FlyBack(float duration)
- {
- float time = 0.0f;
- while (time <= duration)
- {
- float t = time / duration;
- this.transform.position = Vector3.Lerp(transform.position, endPoint.position,t) + (frisbeeCurve.Evaluate(t) * Vector3.left);
- time += Time.deltaTime;
- yield return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment