Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6.  
  7. public class PlayerController : MonoBehaviour
  8. {
  9. public float speed;
  10. public Text countText;
  11. public Text timeText;
  12. public Text boostText;
  13. public Text winText;
  14. private Rigidbody2D rb2d;
  15. private int count;
  16. public int boostCount;
  17. private float timer;
  18. private double timeCompare;
  19. private float timeLeft;
  20. private int movSpeed;
  21. public float x;
  22. public float y;
  23. public float Health;
  24. private Vector2 movement;
  25.  
  26. void Start()
  27. {
  28. rb2d = GetComponent<Rigidbody2D>();
  29. count = 0;
  30. speed = 0.5f;
  31. SetCountText();
  32. winText.text = " ";
  33. boostCount = 0;
  34. boostText.text = "Hit B to use your boost!";
  35. movSpeed = 0;
  36. Health = 100;
  37.  
  38. }
  39.  
  40. void FixedUpdate()
  41. {
  42. // movement, taken from the tutorial
  43. /* float moveHorizontal = Input.GetAxis("Horizontal");
  44. float moveVertical = Input.GetAxis("Vertical");
  45. Vector2 movement = new Vector2(moveHorizontal, moveVertical);
  46. rb2d.AddForce(movement * speed); */
  47.  
  48. /* float moveHorizontal = Input.GetAxis("Horizontal");
  49. float moveVertical = Input.GetAxis("Vertical");
  50. Vector2 movement = new Vector2(moveHorizontal, moveVertical);
  51. rb2d.AddForce(movement * speed); */
  52.  
  53.  
  54. float inputX = Input.GetAxisRaw("Horizontal");
  55. float inputY = Input.GetAxisRaw("Vertical");
  56. movement = new Vector2(inputX, inputY);
  57.  
  58.  
  59. transform.Translate(movement * 50 * Time.deltaTime);
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. // boost
  68. // How the boost works it when B is pressed it takes a time var
  69.  
  70. timer = Mathf.Round(Time.time);
  71. if (Input.GetKeyDown(KeyCode.B) && boostCount == 0)
  72. {
  73. timeCompare = Mathf.Round(Time.fixedTime) + 5;
  74. boostCount = 1;
  75.  
  76. };
  77. if (timer < timeCompare)
  78. {
  79. speed = 150;
  80. }
  81. if (timer > timeCompare)
  82. {
  83.  
  84. speed = 100;
  85.  
  86. }
  87. if(boostCount == 1)
  88. {
  89. boostText.text = "Boost was used!";
  90. }
  91. // debugging countText.text = "Count: " + count.ToString() + " " + speed.ToString() + " " + timer.ToString() + " " + (timeLeft) + " " + timeCompare;
  92. countText.text = "Speed: " + speed + "Weapon:";
  93. timeText.text = "Time: " + timer + " Health:" + Health;
  94. }
  95. void OnTriggerEnter2D(Collider2D other)
  96. {
  97. if (other.gameObject.CompareTag ("Pickup"))
  98. {
  99. other.gameObject.SetActive (false);
  100. count = count + 1;
  101. SetCountText();
  102. }
  103. }
  104. void SetCountText()
  105.  
  106. {
  107. countText.text = "Count: " + speed.ToString() + timer.ToString();
  108. if(count >= 1)
  109. {
  110. winText.text = "You won!";
  111. }
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement