Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class player : MonoBehaviour {
- private Animator anim;
- public GameObject coisadoscore;
- void OnCollisionEnter2D(Collision2D coll)
- {
- if (coll.gameObject.tag == "Gema")
- {
- Destroy(coll.gameObject);
- //Addpontos();
- Pont score = coisadoscore.GetComponent <Pont> () as Pont; //getcomponent puxa as paradinha
- score.Addpontos();
- }
- }
- // Use this for initialization
- void Start () {
- anim = GetComponent<Animator>(); //recebe o animator (controle das animaçoes)
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetAxisRaw("Horizontal") > 0){
- transform.eulerAngles = new Vector2(0, 0);
- transform.Translate(Vector2.right * 0.2f);//anda pra direita por 2
- }
- anim.SetFloat("Walk",Input.GetAxis("Horizontal"));
- if (Input.GetAxisRaw("Horizontal") < 0){
- transform.eulerAngles = new Vector2(0, 180); //flip sintaxe = new vetor (x, y angulo)
- transform.Translate(Vector2.right * 0.2f); // toda vez que ele da um flip, o codigo inverte
- }
- anim.SetFloat("Walk",Mathf.Abs(Input.GetAxis("Horizontal"))); // mathf deixa o valor sempre positivo
- if (Input.GetKey(KeyCode.Space)){
- transform.Translate(Vector2.up * 0.2f);
- anim.SetBool("Jump", true);
- }
- else if (Input.GetKeyUp(KeyCode.Space)) { //quando tira o espaço ele desativa a animaçao de jump
- anim.SetBool("Jump", false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement