Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. public class Player: MonoBehaviour {
  2.  
  3. public Rigidbody2D myRigidbody { get; set; }
  4.  
  5. public float jumpForce = 2.0f;
  6.  
  7. [SerializeField]
  8. public Animator animator;
  9.  
  10. public bool isDead = true;
  11.  
  12. public GameManager gameManager;
  13.  
  14. public bool IsDead
  15. {
  16. get
  17. {
  18. return isDead;
  19. }
  20. }
  21.  
  22. void Start () {
  23. myRigidbody = GetComponent<Rigidbody2D>();
  24. }
  25.  
  26. void Update () {
  27.  
  28. if (Input.GetMouseButtonDown(0) && !IsDead)
  29. {
  30. jump = true;
  31. animator.SetBool("jump", true);
  32. }else
  33. {
  34. animator.SetBool("jump", false);
  35. }
  36. }
  37.  
  38. public void OnTriggerEnter2D(Collider2D collision)
  39. {
  40. if (!isDead && collision.tag == "Obstacle")
  41. {
  42. StartCoroutine(Die());
  43. }
  44.  
  45. }
  46.  
  47. public IEnumerator Die()
  48. {
  49. isDead = true;
  50. animator.SetBool("Die", true);
  51. yield return new WaitForSeconds(2);
  52. gameManager.GameOver();
  53.  
  54. }
  55.  
  56. public void Jump()
  57. {
  58. myRigidbody.AddForce(jumpForce* Vector2.up, ForceMode2D.Impulse);
  59. }
  60.  
  61. public enum GameStates { Start, InGame, GameOver};
  62.  
  63. [SerializeField]
  64. private Player player;
  65.  
  66. [SerializeField]
  67. private Player player1;
  68.  
  69. public GameObject startPanel, ingamePanel, gameoverPanel;
  70.  
  71. void Update () {
  72.  
  73. if(player.IsDead )
  74. {
  75. StartCoroutine(player.Die());
  76. GameOver();
  77.  
  78. }
  79.  
  80. if (player1.IsDead)
  81. {
  82. StartCoroutine(player1.Die());
  83. GameOver();
  84. }
  85. }
  86.  
  87. public void GameOver()
  88. {
  89. UpdateUI(GameStates.GameOver);
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement