Advertisement
Guest User

scripts

a guest
Feb 28th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. Pause.CS
  2.  
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6.  
  7. public class Pause : MonoBehaviour
  8. {
  9.  
  10. public GameObject pausePanel;
  11. public PlayerController controller;
  12.  
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16.  
  17. }
  18.  
  19.  
  20.  
  21. // Update is called once per frame
  22. void Update()
  23. {
  24. if (Input.GetKeyDown(KeyCode.Escape))
  25. {
  26. pausePanel.SetActive(!pausePanel.activeSelf);
  27. controller.isActive = !pausePanel.activeSelf;
  28.  
  29. if (pausePanel.activeSelf)
  30. Time.timeScale = 0;
  31. else
  32. Time.timeScale = 1;
  33.  
  34. // Time.timeScale = pausePanel.activeSelf ? 0 : 1;
  35. }
  36. }
  37.  
  38. public void Unpause()
  39. {
  40. pausePanel.SetActive(!pausePanel.activeSelf);
  41. controller.isActive = !pausePanel.activeSelf;
  42. Time.timeScale = 1;
  43. }
  44.  
  45. public void QuitGame()
  46. {
  47. Application.Quit();
  48. }
  49. }
  50.  
  51.  
  52. StartMenu.cs
  53.  
  54. using System.Collections;
  55. using System.Collections.Generic;
  56. using UnityEngine;
  57. using UnityEngine.SceneManagement;
  58.  
  59. public class StartMenu : MonoBehaviour
  60. {
  61.  
  62. public PlayerController controller;
  63. // Start is called before the first frame update
  64. void Start()
  65. {
  66.  
  67. }
  68.  
  69. // Update is called once per frame
  70. void Update()
  71. {
  72. }
  73.  
  74. public void StartGame()
  75. {
  76. Debug.Log("test");
  77. SceneManager.LoadScene("Gam120Project1");
  78. }
  79.  
  80. public void QuitGame()
  81. {
  82. Application.Quit();
  83. }
  84.  
  85.  
  86. }
  87.  
  88. PlayerController.cs
  89.  
  90. using System.Collections;
  91. using System.Collections.Generic;
  92. using UnityEngine;
  93.  
  94. public class PlayerController : MonoBehaviour
  95. {
  96.  
  97. public float horizontal = 0;
  98. public float vertical = 0;
  99. private Rigidbody2D rb;
  100. [SerializeField]private SpriteRenderer sr;
  101. public float moveSpeed = 5;
  102. private Animator anim;
  103. private float jumpforce = 8;
  104. private bool isjumping = false;
  105. private bool isgrounded = true;
  106.  
  107. public bool isActive = true;
  108. // Start is called before the first frame update
  109. void Start()
  110. {
  111. rb = GetComponent<Rigidbody2D>();
  112. anim = GetComponent<Animator>();
  113. }
  114.  
  115. // Update is called once per frame
  116. void Update()
  117. {
  118. if (isActive)
  119. {
  120. horizontal = Input.GetAxisRaw("Horizontal");
  121. isjumping = Input.GetKeyDown(KeyCode.Space);
  122.  
  123. anim.SetBool("IsMoving", horizontal != 0 || vertical != 0);
  124.  
  125. if (horizontal < 0 && sr.flipX == false)
  126. sr.flipX = true;
  127. else if (horizontal > 0 && sr.flipX == true)
  128. sr.flipX = false;
  129. }
  130.  
  131. }
  132.  
  133. void FixedUpdate()
  134. {
  135. print (isgrounded);
  136.  
  137. Vector2 NewMovement = new Vector2(horizontal, 0).normalized * moveSpeed;
  138.  
  139.  
  140. if (isjumping && isgrounded) NewMovement += new Vector2(0, jumpforce);
  141. else NewMovement += new Vector2(0, rb.velocity.y);
  142.  
  143. rb.velocity = NewMovement;
  144. }
  145.  
  146. private void OnCollisionEnter2D(Collision2D collision)
  147. {
  148. isgrounded = true;
  149. }
  150. private void OnCollisionExit2D(Collision2D collision)
  151. {
  152. isgrounded = false;
  153. }
  154. private void OnCollisionStay2D(Collision2D collision)
  155. {
  156. isgrounded = true;
  157. }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement