Advertisement
dantepw

Player1

Aug 21st, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerMovement : MonoBehaviour {
  5.  
  6.  
  7.     //movimentando
  8.     public float walkSpeed = 10f;
  9.  
  10.     //pulando
  11.     public float alturaPulo = 200f;
  12.     private int numPulos = 0;
  13.     private bool pulouDoChao = false;
  14.  
  15.  
  16.  
  17.     //animaçao
  18. //  Animator anim;
  19. //  float jumpTime, jumpDelay = .5f;
  20.     bool jumped;
  21.  
  22.  
  23.     //variaveis de colisao
  24.     public Transform baixo1, baixo2;
  25.     bool baixo = false;
  26.    
  27.     public Transform cima1, cima2;
  28.     bool cima = false;
  29.    
  30.  
  31.     public Player2 p2;
  32.  
  33.  
  34.  
  35.     //verificando objetos ao redor [chao e outros]
  36.     public bool grounded_p1 = false;
  37.     bool obstacle = false;
  38.  
  39.     // Use this for initialization
  40.     void Start ()
  41.     {
  42.         //anim = GetComponent<Animator> ();
  43.     }
  44.    
  45.  
  46.     void Update ()
  47.     {
  48.         //movimentacao
  49.         float move = Input.GetAxis ("Horizontal_P1");
  50.         rigidbody2D.velocity = new Vector2 (move * walkSpeed, rigidbody2D.velocity.y);
  51.  
  52.  
  53. //      print (rigidbody2D.transform.rotation.z);
  54.  
  55.         isGrounded ();
  56.         overHead ();
  57.  
  58.         //pulo
  59.         if (Input.GetKeyDown (KeyCode.W))
  60.         {
  61.            
  62.             if (obstacle == true && grounded_p1 == false)
  63.             {
  64.                 //print ("sem pulos");
  65.             }
  66.            
  67.             if (numPulos == 0 && grounded_p1 == true) //primeiro pulo
  68.             {
  69.                 pulo ();
  70.                 numPulos = 1;
  71.                 pulouDoChao = true;
  72.             }
  73.         }
  74.     }
  75.  
  76.  
  77.     void FixedUpdate ()
  78.     {
  79.  
  80.     }
  81.    
  82.  
  83.     void pulo()
  84.     {
  85.         rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, 0);
  86.         rigidbody2D.AddForce(new Vector2(0f, alturaPulo));
  87.     }
  88.  
  89.     void RayCasting(string layer)
  90.     {
  91.         Debug.DrawLine (baixo1.position, baixo2.position, Color.green);
  92.         baixo = Physics2D.Linecast (baixo1.position, baixo2.position, 1 << LayerMask.NameToLayer(layer));
  93.        
  94.         Debug.DrawLine (cima1.position, cima2.position, Color.green);
  95.         cima = Physics2D.Linecast (cima1.position, cima2.position, 1 << LayerMask.NameToLayer(layer));
  96.  
  97.     }
  98.  
  99.     void isGrounded()
  100.     {
  101.         RayCasting ("Ground");
  102.        
  103.         if (baixo == true)
  104.         {
  105.             grounded_p1 = true; numPulos = 0;
  106.         }  
  107.  
  108.         else
  109.         {
  110.             grounded_p1 = false;
  111.         }
  112.     }
  113.  
  114.     void overHead ()
  115.     {
  116.         RayCasting ("Player");
  117.        
  118.         if (cima == true)
  119.         {
  120.             print ("cabeça P2");
  121.         }
  122.        
  123.         if (baixo == true)
  124.         {
  125.             rigidbody2D.AddForce(new Vector2(0f, 700));
  126.         }
  127.     }
  128.  
  129.  
  130.  
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement