Advertisement
CarlosWGama

Untitled

Sep 29th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement