Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class player : MonoBehaviour {
  5.  
  6. private Animator anim;
  7.  
  8. public GameObject coisadoscore;
  9.  
  10. void OnCollisionEnter2D(Collision2D coll)
  11. {
  12. if (coll.gameObject.tag == "Gema")
  13. {
  14. Destroy(coll.gameObject);
  15. //Addpontos();
  16. Pont score = coisadoscore.GetComponent <Pont> () as Pont; //getcomponent puxa as paradinha
  17. score.Addpontos();
  18. }
  19.  
  20. }
  21. // Use this for initialization
  22. void Start () {
  23.  
  24. anim = GetComponent<Animator>(); //recebe o animator (controle das animaçoes)
  25.  
  26. }
  27.  
  28. // Update is called once per frame
  29. void Update () {
  30.  
  31. if (Input.GetAxisRaw("Horizontal") > 0){
  32. transform.eulerAngles = new Vector2(0, 0);
  33. transform.Translate(Vector2.right * 0.2f);//anda pra direita por 2
  34. }
  35.  
  36. anim.SetFloat("Walk",Input.GetAxis("Horizontal"));
  37.  
  38. if (Input.GetAxisRaw("Horizontal") < 0){
  39. transform.eulerAngles = new Vector2(0, 180); //flip sintaxe = new vetor (x, y angulo)
  40. transform.Translate(Vector2.right * 0.2f); // toda vez que ele da um flip, o codigo inverte
  41. }
  42.  
  43. anim.SetFloat("Walk",Mathf.Abs(Input.GetAxis("Horizontal"))); // mathf deixa o valor sempre positivo
  44.  
  45. if (Input.GetKey(KeyCode.Space)){
  46. transform.Translate(Vector2.up * 0.2f);
  47. anim.SetBool("Jump", true);
  48. }
  49.  
  50. else if (Input.GetKeyUp(KeyCode.Space)) { //quando tira o espaço ele desativa a animaçao de jump
  51. anim.SetBool("Jump", false);
  52. }
  53.  
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement