Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour
  6. {
  7. public float velocidade;
  8. public float alturaPulo;
  9.  
  10. private Animator anim;
  11. public Transform player;
  12.  
  13. public Rigidbody2D playerRigidbody;
  14.  
  15. public Transform ground;
  16. public bool grounded;
  17. public LayerMask whatIsGround;
  18.  
  19. public GameObject gameOver;
  20.  
  21. public AudioClip somMoeda;
  22.  
  23. // Start is called before the first frame update
  24. void Start()
  25. {
  26. anim = player.GetComponent<Animator>();
  27. gameOver.SetActive(false);
  28. }
  29.  
  30. // Update is called once per frame
  31. void Update()
  32. {
  33. Movimentar();
  34. Jump();
  35. }
  36.  
  37. void Movimentar()
  38. {
  39. if (Input.GetAxis("Horizontal") > 0)
  40.  
  41. {
  42. transform.Translate(Vector2.right * velocidade * Time.deltaTime);
  43. }
  44. if (Input.GetAxis("Horizontal") < 0)
  45. {
  46. transform.Translate(Vector2.left * velocidade * Time.deltaTime);
  47. }
  48.  
  49. }
  50.  
  51.  
  52. void Jump()
  53. {
  54. grounded = Physics2D.OverlapCircle(ground.position, 0.2f, whatIsGround);
  55. //anim.SetBool("Jump", !grounded);
  56.  
  57. if (Input.GetButtonDown("Jump") && grounded == true)
  58. {
  59.  
  60. playerRigidbody.AddForce(Vector2.up * alturaPulo);
  61.  
  62. }
  63. }
  64.  
  65.  
  66. void OnTriggerEnter2D(Collider2D other)
  67. {
  68. if (other.CompareTag("Enemy"))
  69. {
  70. Destroy(gameObject);
  71. gameOver.SetActive(true);
  72. }
  73. if (other.CompareTag("Moedas"))
  74. {
  75. Destroy(other.gameObject);
  76. ScoreScript.score += 10;
  77. SoundManagerScript.PlaySound("coin");
  78. }
  79.  
  80. }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement