Advertisement
Ximbola

UNITY - Todas as movimentações personagem 2D FULL Animator

Dec 16th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class estudo : MonoBehaviour {
  5.  
  6.     public  Animator        anim;
  7.     public  Rigidbody2D     playerRigidibody;
  8.     private bool            andar;
  9.  
  10.     private float           horizontal;
  11.     public  float           velocidade;
  12.     public  float           forcaPulo;
  13.  
  14.     public  bool            olhandoDireita;
  15.  
  16.     public  bool            pisandoNoChao;
  17.     public  Transform       groundCheck;
  18.     public  LayerMask       whatsIsGround; //permite selecionar Layers
  19.  
  20.     // Use this for initialization
  21.     void Start () {
  22.  
  23.     }
  24.    
  25.     // Update is called once per frame
  26.     void Update () {
  27.  
  28.         horizontal = Input.GetAxisRaw("Horizontal");
  29.  
  30.         pisandoNoChao = Physics2D.OverlapCircle(groundCheck.position,0.02f, whatsIsGround);
  31.  
  32.         if (Input.GetButtonDown ("Jump")&& pisandoNoChao == true) {
  33.        
  34.             playerRigidibody.AddForce(new Vector2(0, forcaPulo));
  35.         }
  36.  
  37.  
  38.         if (horizontal > 0 && olhandoDireita == false) {
  39.  
  40.             virarPersonagem ();
  41.         } else if (horizontal < 0 && olhandoDireita == true) {
  42.        
  43.             virarPersonagem(); 
  44.         }
  45.  
  46.         playerRigidibody.velocity = new Vector2 (horizontal*velocidade,playerRigidibody.velocity.y);
  47.  
  48.         if (horizontal != 0) {
  49.  
  50.             andar = true;
  51.         } else {
  52.        
  53.             andar = false;
  54.         }
  55.    
  56.         anim.SetBool ("andar", andar);
  57.         anim.SetBool ("pisandoChaoAnimator",pisandoNoChao);
  58.         anim.SetFloat ("velocidadeY",playerRigidibody.velocity.y);
  59.  
  60.     }
  61.  
  62.     void virarPersonagem(){
  63.    
  64.         olhandoDireita = !olhandoDireita;
  65.         Vector3 theScale = transform.localScale;
  66.         theScale.x *= -1;
  67.         transform.localScale = theScale;
  68.  
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement