Advertisement
rodrigofbm

lololo

Apr 29th, 2015
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.     var velocidade : float;
  3.     var pulo : float = 60;
  4.     var InicioRay: Transform;
  5.     var FimRay: Transform;
  6.     var Chao: boolean;
  7.     var Animacao : Animator;
  8.    
  9.     var Agarrou : boolean;
  10.     var InicioAgarrarTop : Transform;
  11.     var FimAgarrarTop : Transform;
  12.     var InicioAgarrarBot : Transform;
  13.     var FimAgarrarBot : Transform;
  14.     var Subindo : boolean;
  15. static  var Empurrar : boolean;
  16.    
  17. function Start ()
  18. {
  19.        
  20.     velocidade = 30;
  21.    
  22. }
  23.  
  24. function Update ()
  25. {
  26.     RayCasting();
  27.    
  28.    
  29.    
  30.    
  31.     //transform.position.x += Input.GetAxis("Horizontal")*velocidade*Time.deltaTime;
  32.     transform.GetComponent.<Rigidbody2D>().velocity.x = velocidade * Input.GetAxis("Horizontal");
  33.    
  34.     if(Input.GetAxis("Horizontal") != 0 && !Subindo)
  35.     {
  36.    
  37.     if(!Empurrar)
  38.     {
  39.     if(Input.GetAxis("Horizontal") > 0)
  40.         {
  41.             transform.localScale.x = 1;
  42.         }
  43.     else
  44.         {
  45.             transform.localScale.x = -1;
  46.         }  
  47.     }
  48.     }
  49.     if(Input.GetKey("left shift") && Input.GetAxis("Horizontal"))
  50.         {
  51.             velocidade = 50;
  52.             Animacao.SetBool("Correndo", true);
  53.         }  
  54.         else
  55.                 {
  56.                 velocidade = 30;
  57.                 Animacao.SetBool("Correndo", false);
  58.                 }
  59.    
  60.         if(Input.GetButtonDown("Jump") && Chao)
  61.             {
  62.                 GetComponent.<Rigidbody2D>().velocity.y = pulo;
  63.             }
  64.         if(Input.GetButtonUp("Jump") && !Chao && GetComponent.<Rigidbody2D>().velocity.y >0)
  65.             {
  66.                 GetComponent.<Rigidbody2D>().velocity.y = GetComponent.<Rigidbody2D>().velocity.y/2;
  67.             }
  68.        
  69.        
  70.         if(!Chao)
  71.             {
  72.                 if(GetComponent.<Rigidbody2D>().velocity.y < 0)
  73.                     {
  74.                         Animacao.SetBool("Caindo", true);
  75.                     }
  76.                 if(GetComponent.<Rigidbody2D>().velocity.y > 0)
  77.                     {
  78.                         Animacao.SetBool("Pulando", true);
  79.                        
  80.                     }
  81.                 if(Agarrou)
  82.                     {
  83.                         Animacao.SetBool("Agarrado", true);
  84.                     }
  85.                 if(!Agarrou)
  86.                     {
  87.                         Animacao.SetBool("Agarrado", false);
  88.                     }                      
  89.        
  90.             }
  91.         if(Chao)
  92.             {
  93.                 Animacao.SetFloat("Andando", Mathf.Abs(Input.GetAxis("Horizontal")));
  94.                 Animacao.SetBool("Caindo", false);
  95.                 Animacao.SetBool("Pulando", false);
  96.                 Agarrou = false;
  97.                
  98.                
  99.             }  
  100.            
  101.         if(Agarrou)
  102.         {
  103.             GetComponent.<Rigidbody2D>().isKinematic = true;
  104.             velocidade = 0;
  105.                 if(Input.GetAxis("Vertical") > 0)
  106.                     {
  107.                         Subindo = true;
  108.                     }
  109.         }
  110.         if(!Agarrou ||  Input.GetAxis("Vertical") < 0)
  111.             {
  112.                 GetComponent.<Rigidbody2D>().isKinematic = false;
  113.             }
  114.            
  115.             if(Subindo)
  116.                 {   Tsubindo();
  117.                     GetComponent.<Rigidbody2D>().isKinematic = true;
  118.                     GetComponent.<Rigidbody2D>().gravityScale = 0;
  119.                     if(transform.localScale.x == 1)
  120.                     {
  121.                     GetComponent.<Rigidbody2D>().transform.Translate(Vector2(3 * Time.deltaTime, 18 * Time.deltaTime));
  122.                     }
  123.                     if(transform.localScale.x == -1)
  124.                     {
  125.                     GetComponent.<Rigidbody2D>().transform.Translate(Vector2(-3 * Time.deltaTime, 18 * Time.deltaTime));
  126.                     }
  127.                     Animacao.SetBool("Subindo", true);
  128.                 }
  129.             if(!Subindo)
  130.                 {
  131.                     GetComponent.<Rigidbody2D>().gravityScale = 10;
  132.                     Animacao.SetBool("Subindo", false);
  133.                 }
  134.                
  135.  
  136.             if(Empurrar && Input.GetKey("f") && Chao && Input.GetAxis("Horizontal"))
  137.              {
  138.                     Animacao.SetBool("Correndo", false);
  139.                    
  140.                    
  141.                     if(transform.localScale == 1)
  142.                     {
  143.                         if(Input.GetAxis("Horizontal") > 0)
  144.                             {
  145.                             Animacao.SetBool("Empurrando", true);
  146.                             Animacao.SetBool("Puxar", false);
  147.                             }
  148.                         if(Input.GetAxis("Horizontal") < 0)
  149.                             {
  150.                             velocidade = 10;
  151.                             Animacao.SetBool("Empurrando", false);
  152.                             Animacao.SetBool("Puxar", true);
  153.                            
  154.                             }  
  155.                    
  156.                     }
  157.                    
  158.                     else
  159.                     {
  160.                         if(Input.GetAxis("Horizontal") > 0)
  161.                             {
  162.                             velocidade = 10;
  163.                             Animacao.SetBool("Empurrando", false);
  164.                             Animacao.SetBool("Puxar", true);
  165.                             }
  166.                         if(Input.GetAxis("Horizontal") < 0)
  167.                             {
  168.                             Animacao.SetBool("Empurrando", true);
  169.                             Animacao.SetBool("Puxar", false);
  170.                             }  
  171.                    
  172.                     }
  173.                    
  174.                  }
  175.                 else
  176.                     {
  177.                     Animacao.SetBool("Empurrando", false);
  178.                     Animacao.SetBool("Puxar", false);
  179.                     }
  180.                    
  181.                
  182.            
  183. }
  184.  
  185. function RayCasting()
  186. {
  187.    
  188.         Debug.DrawLine(InicioRay.position, FimRay.position, Color.red);
  189.         Debug.DrawLine(InicioAgarrarTop.position, FimAgarrarTop.position, Color.blue);
  190.         Debug.DrawLine(InicioAgarrarBot.position, FimAgarrarBot.position, Color.blue);
  191.        
  192.         if(!Physics2D.Linecast(InicioAgarrarTop.position, FimAgarrarTop.position) &&
  193.             Physics2D.Linecast(InicioAgarrarBot.position, FimAgarrarBot.position))
  194.             {
  195.                 if(GetComponent.<Rigidbody2D>().velocity.y < 0)
  196.                 {
  197.                 Agarrou = true;
  198.                 }
  199.             }
  200.             else
  201.                 {
  202.                     Agarrou = false;
  203.                 }
  204.        
  205.        
  206.         if(Physics2D.Linecast(InicioRay.position, FimRay.position))
  207.         {
  208.             Chao = true;
  209.         }
  210.  
  211.         else
  212.         {
  213.         Chao = false;
  214.         }
  215.         }
  216.        
  217.        
  218. function Tsubindo()
  219. {
  220.         if(Subindo == true)
  221.         {
  222.             yield WaitForSeconds (1.4);
  223.             Subindo = false;
  224.         }
  225.  
  226. }
  227.  
  228.        
  229. function OnTriggerEnter2D(Colisao : Collider2D)
  230. {
  231.         if(Colisao.gameObject.tag == "Box" )
  232.         {
  233.             Empurrar = true;
  234.            
  235.         }
  236.        
  237. }
  238.  
  239. function OnTriggerExit2D(Colisao : Collider2D)
  240. {
  241.         if(Colisao.gameObject.tag == "Box")
  242.         {
  243.         Empurrar = false;
  244.        
  245.         }
  246.        
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement