Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- var velocidade : float;
- var pulo : float = 60;
- var InicioRay: Transform;
- var FimRay: Transform;
- var Chao: boolean;
- var Animacao : Animator;
- var Agarrou : boolean;
- var InicioAgarrarTop : Transform;
- var FimAgarrarTop : Transform;
- var InicioAgarrarBot : Transform;
- var FimAgarrarBot : Transform;
- var Subindo : boolean;
- static var Empurrar : boolean;
- function Start ()
- {
- velocidade = 30;
- }
- function Update ()
- {
- RayCasting();
- //transform.position.x += Input.GetAxis("Horizontal")*velocidade*Time.deltaTime;
- transform.GetComponent.<Rigidbody2D>().velocity.x = velocidade * Input.GetAxis("Horizontal");
- if(Input.GetAxis("Horizontal") != 0 && !Subindo)
- {
- if(!Empurrar)
- {
- if(Input.GetAxis("Horizontal") > 0)
- {
- transform.localScale.x = 1;
- }
- else
- {
- transform.localScale.x = -1;
- }
- }
- }
- if(Input.GetKey("left shift") && Input.GetAxis("Horizontal"))
- {
- velocidade = 50;
- Animacao.SetBool("Correndo", true);
- }
- else
- {
- velocidade = 30;
- Animacao.SetBool("Correndo", false);
- }
- if(Input.GetButtonDown("Jump") && Chao)
- {
- GetComponent.<Rigidbody2D>().velocity.y = pulo;
- }
- if(Input.GetButtonUp("Jump") && !Chao && GetComponent.<Rigidbody2D>().velocity.y >0)
- {
- GetComponent.<Rigidbody2D>().velocity.y = GetComponent.<Rigidbody2D>().velocity.y/2;
- }
- if(!Chao)
- {
- if(GetComponent.<Rigidbody2D>().velocity.y < 0)
- {
- Animacao.SetBool("Caindo", true);
- }
- if(GetComponent.<Rigidbody2D>().velocity.y > 0)
- {
- Animacao.SetBool("Pulando", true);
- }
- if(Agarrou)
- {
- Animacao.SetBool("Agarrado", true);
- }
- if(!Agarrou)
- {
- Animacao.SetBool("Agarrado", false);
- }
- }
- if(Chao)
- {
- Animacao.SetFloat("Andando", Mathf.Abs(Input.GetAxis("Horizontal")));
- Animacao.SetBool("Caindo", false);
- Animacao.SetBool("Pulando", false);
- Agarrou = false;
- }
- if(Agarrou)
- {
- GetComponent.<Rigidbody2D>().isKinematic = true;
- velocidade = 0;
- if(Input.GetAxis("Vertical") > 0)
- {
- Subindo = true;
- }
- }
- if(!Agarrou || Input.GetAxis("Vertical") < 0)
- {
- GetComponent.<Rigidbody2D>().isKinematic = false;
- }
- if(Subindo)
- { Tsubindo();
- GetComponent.<Rigidbody2D>().isKinematic = true;
- GetComponent.<Rigidbody2D>().gravityScale = 0;
- if(transform.localScale.x == 1)
- {
- GetComponent.<Rigidbody2D>().transform.Translate(Vector2(3 * Time.deltaTime, 18 * Time.deltaTime));
- }
- if(transform.localScale.x == -1)
- {
- GetComponent.<Rigidbody2D>().transform.Translate(Vector2(-3 * Time.deltaTime, 18 * Time.deltaTime));
- }
- Animacao.SetBool("Subindo", true);
- }
- if(!Subindo)
- {
- GetComponent.<Rigidbody2D>().gravityScale = 10;
- Animacao.SetBool("Subindo", false);
- }
- if(Empurrar && Input.GetKey("f") && Chao && Input.GetAxis("Horizontal"))
- {
- Animacao.SetBool("Correndo", false);
- if(transform.localScale == 1)
- {
- if(Input.GetAxis("Horizontal") > 0)
- {
- Animacao.SetBool("Empurrando", true);
- Animacao.SetBool("Puxar", false);
- }
- if(Input.GetAxis("Horizontal") < 0)
- {
- velocidade = 10;
- Animacao.SetBool("Empurrando", false);
- Animacao.SetBool("Puxar", true);
- }
- }
- else
- {
- if(Input.GetAxis("Horizontal") > 0)
- {
- velocidade = 10;
- Animacao.SetBool("Empurrando", false);
- Animacao.SetBool("Puxar", true);
- }
- if(Input.GetAxis("Horizontal") < 0)
- {
- Animacao.SetBool("Empurrando", true);
- Animacao.SetBool("Puxar", false);
- }
- }
- }
- else
- {
- Animacao.SetBool("Empurrando", false);
- Animacao.SetBool("Puxar", false);
- }
- }
- function RayCasting()
- {
- Debug.DrawLine(InicioRay.position, FimRay.position, Color.red);
- Debug.DrawLine(InicioAgarrarTop.position, FimAgarrarTop.position, Color.blue);
- Debug.DrawLine(InicioAgarrarBot.position, FimAgarrarBot.position, Color.blue);
- if(!Physics2D.Linecast(InicioAgarrarTop.position, FimAgarrarTop.position) &&
- Physics2D.Linecast(InicioAgarrarBot.position, FimAgarrarBot.position))
- {
- if(GetComponent.<Rigidbody2D>().velocity.y < 0)
- {
- Agarrou = true;
- }
- }
- else
- {
- Agarrou = false;
- }
- if(Physics2D.Linecast(InicioRay.position, FimRay.position))
- {
- Chao = true;
- }
- else
- {
- Chao = false;
- }
- }
- function Tsubindo()
- {
- if(Subindo == true)
- {
- yield WaitForSeconds (1.4);
- Subindo = false;
- }
- }
- function OnTriggerEnter2D(Colisao : Collider2D)
- {
- if(Colisao.gameObject.tag == "Box" )
- {
- Empurrar = true;
- }
- }
- function OnTriggerExit2D(Colisao : Collider2D)
- {
- if(Colisao.gameObject.tag == "Box")
- {
- Empurrar = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement