Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class SimpleMove : MonoBehaviour {
  7.  
  8. [SerializeField] GameObject score;
  9. [SerializeField] GameObject coin;
  10. int scoreAmount = 0;
  11.  
  12. bool PickedUp = false;
  13. float timeSincePickup = 0f;
  14. private void Update()
  15. {
  16. if (PickedUp)
  17. {
  18. timeSincePickup += Time.deltaTime;
  19. }
  20. if (timeSincePickup >= 2f)
  21. {
  22. PickedUp = false;
  23. timeSincePickup = 0f;
  24. }
  25. if (Input.GetKey(KeyCode.D))
  26. {
  27. transform.position = transform.position + new Vector3(1f * Time.deltaTime, 0, 0);
  28. }
  29.  
  30. if (Input.GetKey(KeyCode.A))
  31. {
  32. transform.position = transform.position + new Vector3(-1f * Time.deltaTime, 0, 0);
  33. }
  34. }
  35.  
  36. private void OnTriggerEnter(Collider other)
  37. {
  38. if (other.name == "Coin")
  39. {
  40. scoreAmount++;
  41. score.GetComponent<Text>().text = "" + scoreAmount;
  42. Destroy(other.gameObject);
  43. StartCoroutine(AnimateScoreUI());
  44. }
  45. }
  46.  
  47. IEnumerator AnimateScoreUI()
  48. {
  49. if (!PickedUp)
  50. {
  51. PickedUp = true;
  52. Vector3 sStart = new Vector3(0f, 30f, 0f);
  53. Vector3 sEnd = new Vector3(0, 0, 0);
  54. Vector3 cStart = new Vector3(20f, 30f, 0f);
  55. Vector3 cEnd = new Vector3(20f, 0f, 0f);
  56. bool done = false;
  57. float percent = 0f;
  58. while (!done)
  59. {
  60.  
  61. percent += Time.deltaTime;
  62. score.transform.localPosition = Vector3.Lerp(sStart, sEnd, percent);
  63. coin.transform.localPosition = Vector3.Lerp(cStart, cEnd, percent);
  64. coin.transform.Rotate(Vector3.Lerp(coin.transform.rotation.eulerAngles, new Vector3(0f, 360f, 0f), percent));
  65. yield return new WaitForEndOfFrame();
  66. if (percent >= 1f)
  67. {
  68. done = true;
  69. }
  70. }
  71.  
  72. while (PickedUp == true)
  73. {
  74. yield return new WaitForSeconds(1);
  75. }
  76.  
  77. done = false;
  78. percent = 0f;
  79. while (!done)
  80. {
  81.  
  82. percent += Time.deltaTime;
  83. score.transform.localPosition = Vector3.Lerp(sEnd, sStart, percent);
  84. coin.transform.localPosition = Vector3.Lerp(cStart, cEnd, percent);
  85. yield return new WaitForEndOfFrame();
  86. if (percent >= 1f)
  87. {
  88. done = true;
  89. }
  90. }
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement