Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BallMovement : MonoBehaviour
  6. {
  7. private Vector3 startPosition;
  8. private Vector3 currentPosition;
  9. private float currTime;
  10. private float aTime;
  11. private bool hasPeeked;
  12. private bool hasMinPeek;
  13. private bool key;
  14. private Rigidbody body;
  15. [Range(0.0f, 5.0f)] public float speed = 0.1f;
  16. [Range(0.0f, 25.0f)] public float distance = 5.0f;
  17. // Start is called before the first frame update
  18. void Start()
  19. {
  20. body = GetComponent<Rigidbody>();
  21. startPosition = transform.position;
  22. currentPosition = startPosition;
  23. hasPeeked = false;
  24. hasMinPeek = false;
  25. }
  26.  
  27. // Update is called once per frame
  28. void Update()
  29. {
  30. if (Input.GetMouseButton(0))
  31. key = true;
  32. if (key)
  33. {
  34. aTime = Time.deltaTime * 5.0f;
  35.  
  36. if(transform.position.y >= 5.31f && !hasMinPeek)
  37. {
  38. transform.position = new Vector3(transform.position.x, transform.position.y - aTime, transform.position.z);
  39. currentPosition = transform.position;
  40. if (transform.position.y <= 5.31f)
  41. hasMinPeek = true;
  42. }
  43. else if (transform.position.y <= 8.73f && !hasPeeked)
  44. {
  45. transform.position = new Vector3(transform.position.x, transform.position.y + aTime, transform.position.z);
  46. currentPosition = transform.position;
  47. if (transform.position.y >= 8.73f)
  48. hasPeeked = true;
  49. }
  50. else if (hasPeeked)
  51. {
  52. // transform.position = new Vector3(transform.position.x, transform.position.y - aTime, transform.position.z);
  53. // currentPosition = transform.position;
  54. body.constraints = RigidbodyConstraints.None;
  55. }
  56.  
  57. }
  58. if (!key)
  59. {
  60. currTime = Time.time;
  61. currentPosition = startPosition + new Vector3(Mathf.Sin(currTime * speed) * distance, 0.0f, 0.0f);
  62. transform.position = currentPosition;
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement