SHARE
TWEET

Untitled

CarlosWGama Sep 29th, 2016 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Player : MonoBehaviour {
  5.  
  6.     public float velocidade;
  7.     public float forcaPulo;
  8.     private bool estaNoChao;
  9.     public Transform chaoVerificador;
  10.  
  11.     /********************* AQUI ***************************/
  12.     private Rigidbody2D rigidbody2D;
  13.     /********************* AQUI ***************************/
  14.     // Use this for initialization
  15.     void Start () {
  16.         /********************* E AQUI ***************************/
  17.         rigidbody2D = GetComponent<Rigidbody2D>();
  18.         /********************* E AQUI ***************************/
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update () {
  23.         Movimentacao();
  24.     }
  25.  
  26.     void Movimentacao() {
  27.  
  28.         estaNoChao = Physics2D.Linecast(transform.position, chaoVerificador.position, 1 << LayerMask.NameToLayer("Piso"));
  29.         if (Input.GetAxisRaw("Horizontal") > 0 ) {
  30.             transform.Translate (Vector2.right * velocidade * Time.deltaTime);
  31.             transform.eulerAngles = new Vector2(0, 0);
  32.         }
  33.  
  34.         if (Input.GetAxisRaw("Horizontal") < 0 ) {
  35.             transform.Translate (Vector2.right * velocidade * Time.deltaTime);
  36.             transform.eulerAngles = new Vector2(0, 180);
  37.         }
  38.  
  39.         if (Input.GetButtonDown("Jump") && estaNoChao) {
  40.             rigidbody2D.AddForce(transform.up * forcaPulo);
  41.         }
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top