Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour
- {
- public float velocidade;
- public float alturaPulo;
- private Animator anim;
- public Transform player;
- public Rigidbody2D playerRigidbody;
- public Transform ground;
- public bool grounded;
- public LayerMask whatIsGround;
- public GameObject gameOver;
- public AudioClip somMoeda;
- // Start is called before the first frame update
- void Start()
- {
- anim = player.GetComponent<Animator>();
- gameOver.SetActive(false);
- }
- // Update is called once per frame
- void Update()
- {
- Movimentar();
- Jump();
- }
- void Movimentar()
- {
- if (Input.GetAxis("Horizontal") > 0)
- {
- transform.Translate(Vector2.right * velocidade * Time.deltaTime);
- }
- if (Input.GetAxis("Horizontal") < 0)
- {
- transform.Translate(Vector2.left * velocidade * Time.deltaTime);
- }
- }
- void Jump()
- {
- grounded = Physics2D.OverlapCircle(ground.position, 0.2f, whatIsGround);
- //anim.SetBool("Jump", !grounded);
- if (Input.GetButtonDown("Jump") && grounded == true)
- {
- playerRigidbody.AddForce(Vector2.up * alturaPulo);
- }
- }
- void OnTriggerEnter2D(Collider2D other)
- {
- if (other.CompareTag("Enemy"))
- {
- Destroy(gameObject);
- gameOver.SetActive(true);
- }
- if (other.CompareTag("Moedas"))
- {
- Destroy(other.gameObject);
- ScoreScript.score += 10;
- SoundManagerScript.PlaySound("coin");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement