Guest User

Untitled

a guest
Jan 31st, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. private BallMovement ballMovement;
  2.     public AnimationCurve frisbeeCurve = new AnimationCurve();
  3.     [SerializeField] float duration;
  4.  
  5.  
  6.     public Transform endPoint;
  7.     void Start()
  8.     {
  9.         ballMovement = (BallMovement)Random.Range(0, 4);
  10.         if (ballMovement == BallMovement.left)
  11.         {
  12.             transform.position = GameManager.instance.leftPosition.position;
  13.             endPoint = GameManager.instance.rightPosition;
  14.             endPoint.position = new Vector3(endPoint.position.x, Random.Range((endPoint.position.y - 300), (endPoint.position.y + 300)), endPoint.position.z);
  15.         }
  16.         else if (ballMovement == BallMovement.right)
  17.         {
  18.             return;
  19.         }
  20.         else if (ballMovement == BallMovement.top)
  21.         {
  22.             return;
  23.         }
  24.         else if (ballMovement == BallMovement.Down)
  25.         {
  26.             return;
  27.         }
  28.  
  29.        
  30.             GetComponent<RectTransform>().DOMove(endPoint.position, 4f);
  31.  
  32.        
  33.     }
  34.  
  35.     private void OnTriggerEnter2D(Collider2D other)
  36.     {
  37.         if (ballMovement == BallMovement.left && other.gameObject.CompareTag("flip"))
  38.         {
  39.             DOTween.Kill(this.gameObject);
  40.             Debug.Log("Trigger");
  41.             StartCoroutine(FlyBack(duration));
  42.          
  43.         }
  44.  
  45.  
  46.     }
  47.  
  48.     IEnumerator FlyBack(float duration)
  49.     {
  50.  
  51.         float time = 0.0f;
  52.  
  53.  
  54.         while (time <= duration)
  55.         {
  56.             float t = time / duration;
  57.             this.transform.position = Vector3.Lerp(transform.position, endPoint.position,t) + (frisbeeCurve.Evaluate(t) * Vector3.left);
  58.  
  59.             time += Time.deltaTime;
  60.             yield return null;
  61.         }
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment